keijiro / KlakNDI

NDI® plugin for Unity
https://ndi.video
Other
747 stars 135 forks source link

Api Compatibility Level .Net 4.x problem #72

Closed sasa42 closed 2 years ago

sasa42 commented 3 years ago

tested in Unity 2019.4.2fa and Unity2019.4.3f1

To reproduce switch your Project with the TestCard scene to Api Compatibility Level .Net 4.x

switching to Api Compatibility Level .Net 4.x is resulting in following error

Error: Could not load signature of Klak.Ndi.Interop.Find:get_CurrentSources due to: Could not load file or assembly 'System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. assembly:System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 type: member:(null) signature:

a build results in Packages\jp.keijiro.klak.ndi\Runtime\Interop\Find.cs(26,19): error CS0246: The type or namespace name 'Span<>' could not be found (are you missing a using directive or an assembly reference?)

Would it be possible to make it compatibel with .Net 4.x ? NDI is the only method i found (Spout and DesktopDuplication is currently only DX11) i can stream to DX12 scenes with Raytracing enabled. Thanks.

keijiro commented 3 years ago

There is a compatibility issue in UnityNuGet packages with .NET 4.x profile. Some users found the same issue in the LASP package.

https://github.com/keijiro/Lasp/issues/28

You can solve the issue with manually importing the System.Buffer and System.Memory packages, and removing the dependency from package.json.

There is another hacky way to work around the issue: Navigate to Player Settings -> Other Settings, then edit Script Define Symbols to add NET_STANDARD_2_0.

image

Although this could cause another issue in another package, you can successfully avoid the problem if you're lucky enough.

sasa42 commented 3 years ago

Thanks for the help.

I removed

"org.nuget.system.buffers": { "version": "4.5.1", "depth": 2, "source": "registry", "dependencies": {}, "url": "https://unitynuget-registry.azurewebsites.net" }, "org.nuget.system.memory": { "version": "4.5.4", "depth": 1, "source": "registry", "dependencies": { "org.nuget.system.buffers": "4.5.1", "org.nuget.system.numerics.vectors": "4.4.0", "org.nuget.system.runtime.compilerservices.unsafe": "4.5.3" }, "url": "https://unitynuget-registry.azurewebsites.net" },

and

"org.nuget.system.memory": "4.5.4" from

"jp.keijiro.klak.ndi": { "version": "file:jp.keijiro.klak.ndi", "depth": 0, "source": "embedded", "dependencies": { "org.nuget.system.memory": "4.5.4" } },

in packages-lock.json.

Then manually imported the two Packages System.Buffer and System.Memory to a \KlakNDI\LocalPackages Folder with the Package Manager + icon.

Something i do wrong here. System.Buffer and System.Memory are always reimported again and the packages-lock.json is reseted to original.

sasa42 commented 3 years ago

my packages-lock.json looks like this

{ "dependencies": { "com.unity.render-pipelines.core": { "version": "7.4.1", "depth": 1, "source": "registry", "dependencies": { "com.unity.ugui": "1.0.0" }, "url": "https://packages.unity.com" }, "com.unity.render-pipelines.universal": { "version": "7.4.1", "depth": 0, "source": "registry", "dependencies": { "com.unity.render-pipelines.core": "7.4.1", "com.unity.shadergraph": "7.4.1" }, "url": "https://packages.unity.com" }, "com.unity.shadergraph": { "version": "7.4.1", "depth": 1, "source": "registry", "dependencies": { "com.unity.render-pipelines.core": "7.4.1" }, "url": "https://packages.unity.com" }, "com.unity.ugui": { "version": "1.0.0", "depth": 2, "source": "builtin", "dependencies": { "com.unity.modules.ui": "1.0.0" } }, "jp.keijiro.klak.ndi": { "version": "file:jp.keijiro.klak.ndi", "depth": 0, "source": "embedded", "dependencies": {} }, "org.nuget.system.numerics.vectors": { "version": "4.4.0", "depth": 2, "source": "registry", "dependencies": {}, "url": "https://unitynuget-registry.azurewebsites.net" }, "org.nuget.system.runtime.compilerservices.unsafe": { "version": "4.5.3", "depth": 2, "source": "registry", "dependencies": {}, "url": "https://unitynuget-registry.azurewebsites.net" }, "com.unity.modules.ui": { "version": "1.0.0", "depth": 3, "source": "builtin", "dependencies": {} } } }

sasa42 commented 3 years ago

an my manifest

{ "scopedRegistries": [ { "name": "Unity NuGet", "url": "https://unitynuget-registry.azurewebsites.net", "scopes": [ "org.nuget" ] }, { "name": "Keijiro", "url": "https://registry.npmjs.com", "scopes": [ "jp.keijiro" ] } ], "dependencies": { "com.unity.render-pipelines.universal": "7.4.1", "org.nuget.system.buffers": "file:../LocalPackages/org.nuget.system.buffers@4.5.1", "org.nuget.system.memory": "file:../LocalPackages/org.nuget.system.memory@4.5.4" } }

sasa42 commented 3 years ago

after a restart i always get the original packages-lock.json. Do you have an idea what i do wrong here.

I am sure did not completly understand your adwise

"You can solve the issue with manually importing the System.Buffer and System.Memory packages, and removing the dependency from package.json."

keijiro commented 3 years ago

Could you try the second workaround?

There is another hacky way to work around the issue: Navigate to Player Settings -> Other Settings, then edit Script Define Symbols to add NET_STANDARD_2_0.

sasa42 commented 3 years ago

Thanks. I was able to build and run your test project with the Script Define Symbol NET_STANDARD_2_0 I also needed to make all packages local because our company firewall and proxy is very picky.

I got this warning. NDI

I will try no to integrate it into my HDRP DXR12 projects.

ToxMox commented 3 years ago

Hey there, Any update on this issue? I'm having the same problem and not able to work around it. I'm using 2020.1.0f because I can't seem to get the 2019 Unity to open a project more than once due to their weird handling of network interfaces with the licensing bug that is fixed in 2020.

keijiro commented 3 years ago

@ToxMox Did you try the NET_STANDARD_2_0 workaround?

https://github.com/keijiro/KlakNDI/issues/72#issuecomment-657301333

ToxMox commented 3 years ago

@keijiro yup. It won't work even with setting the compatibility level to 2.x

You mentioned: "You can solve the issue with manually importing the System.Buffer and System.Memory packages, and removing the dependency from package.json."

I would love to try this but would it be possible to get more specific instructions of what this exactly means please?

Thank you for your time! 👍

keijiro commented 3 years ago

It won't work even with setting the compatibility level to 2.x

That's weird. This issue only happens with the .NET 4.x profile.

Is your issue actually the same as in the first post? https://github.com/keijiro/KlakNDI/issues/72#issue-655386032

ToxMox commented 3 years ago

@keijiro Apologies. I guess it isn't really the same exact error but somewhat adjacent. This is on a fresh 2020.1.0f install > Create new 3D project. > Edit manifest to begin with { "scopedRegistries": [ { "name": "Unity NuGet", "url": "https://unitynuget-registry.azurewebsites.net", "scopes": [ "org.nuget" ] }, { "name": "Keijiro", "url": "https://registry.npmjs.com", "scopes": [ "jp.keijiro" ] } ], "dependencies": { "jp.keijiro.klak.ndi": "1.0.0", image

ToxMox commented 3 years ago

Just wondering. Is this something I can work around or will I need to wait for an update to fix? Or maybe I did something wrong? Should I start a separate issue since this one isn't actually the same as OP?

Thanks!

ahfontaine commented 3 years ago

Hi! I have the same issue as well, but on Span<> in Find.cs.

Soaryn commented 3 years ago

Edit: feels like a different issue, so will be opening a new one.

May be related or the same issue: "Multiple precompiled assemblies with the same name System.Runtime.CompilerServices.Unsafe.dll included or the current platform."

Unity: 2020.2.0a19 Packages of note: Entities .NET Standard 2.0 Klak NDI: 1.0.2

flamacore commented 3 years ago

I believe I found a hacky workaround. Feels like doing something heavily wrong but as the saying goes; if it works and it's stupid, it ain't stupid :)

Unity 2020.1.1f1, HDRP 9.00 (if that matters)

Workaround:

  1. Import everything as usual, as stated in the readme.
  2. Then, copy every package from Package Caches folder related to KlakNDI into the Assets folder.
  3. Remove the dependencies and repositories from the manifest.json.
  4. Select System.Memory.dll and untick 'Validate References'.

After this, our project started to work as expected. But beware, I would consider this highly experimental.

Sampoman commented 3 years ago

Hey,

I've tried to get the package running on two machines (PC and Mac) on a fresh Unity 2019.4.13f1.

Both run into the same two problems:

First I get an error about package resolving, then the issue about Span<> missing. I haven't been able to resolve the issue - NET_STANDARD_2_0 define does not fix the issue, and configuring the packages manually hasn't helped yet so far.

I'd really need to test this, any help would be greatly appreciated!

error1

error2

keijiro commented 3 years ago

@Sampoman It seems that the UnityNuGet registry has a problem. I reported it to the author. https://github.com/xoofx/UnityNuGet/issues/17

keijiro commented 3 years ago

@Sampoman The problem was fixed on the UnityNuGet registry side. Clear the Package Manager cache directory and retry opening the project.

v2k commented 3 years ago

Running into this as well with the latest, what is the recommended solution? I've tried deleting the Package Manager cache to no avail.

Unity2019.4.14f1

keijiro commented 3 years ago

@v2k I'd recommend defining NET_STANDARD_2_0. See: https://github.com/keijiro/KlakNDI/issues/72#issuecomment-657216829

v2k commented 3 years ago

Actually, it looks like it was conflicting with Unity's Collection and Jobs preview packages. Removing those resolved it.

namely:

"com.unity.collections": "0.0.9-preview.12"
"com.unity.jobs": "0.0.7-preview.6"
hybridherbst commented 3 years ago

Hi @keijiro, have you talked to xoofx regarding those compatibility issues, any plans to resolve this?

keijiro commented 3 years ago

@hybridherbst No. My understanding is that it can be resolved by defining NET_STANDARD_2_0.

hybridherbst commented 3 years ago

I find that both very hacky and very dangerous. Setting compile directives for stuff that isn't actually active certainly sounds like a catastrophic failure to happen...

@xoofx maybe you have some input on this?

MichalKolasinski commented 3 years ago

OK. The proble still exists. This is how you can reproduce it:

1) Download project KlakNDI master 2) Open in unity 2020.1.6f1 -> everything is fine. 3) Switch Api Compatibility Level to .Net 4.x in Project settings. 4) Wait for recompile

You get an error: Packages\jp.keijiro.klak.ndi\Runtime\Interop\Find.cs(26,19): error CS0246: The type or namespace name 'Span<>' could not be found (are you missing a using directive or an assembly reference?)

NET_STANDARD_2_0 workaround is not working..

Can you please tell me if this will be resolved? Thank you!

xoofx commented 3 years ago

So I don't understand the problem of this thread clearly, but UnityNuGet doesn't support (and will never) .NET 4.x, so I would advice to not try to workaround that. If you app is still on .NET 4.x migrate it. .NET 4.x is a dead end.

keijiro commented 3 years ago

@xoofx Thanks for the explanation.

So, the conclusion is that the current implementation of KlakNDI doesn't support .NET 4.x. To solve the problem, I have to rewrite several parts of the implementation. I'm not motivated to do so, though.

@hybridherbst Out of curiosity, is there any reason to use .NET 4.x? Is it possible to migrate to .NET Standard 2.0?

hybridherbst commented 3 years ago

@keijiro switching from .NET 4 to .NET Standard 2.0 removes a ton of available libraries. While some of those gone are available on Nuget, adding those often results in dependency clashes to older versions of those that are directly shipping with the Unity Editor, usually unresolvable (at least for us, not sure if there's rcp magic to resolve).

Especially for experiential projects that interface with unusual (and/or older) hardware and software we found switching to be not viable; that being said, for new projects we already try to but sometimes (rarely) run into the same issues.

keijiro commented 3 years ago

@hybridherbst Thanks for the input. Although there is no plan for fixing this issue, now I can understand what the actual problem is.

keijiro commented 3 years ago

Note: This is a known issue of KlakNDI, and there is no plan for fixing it at the moment. I'd like to keep this issue open for future reference.

keijiro commented 2 years ago

Note: The situation will change in Unity 2021.2 because it gets Span<> support in both .NET Standard and .NET Framework profiles. There are still some mix-ups, but I hope I can solve the issues in the released version of 2021.2.

keijiro commented 2 years ago

I confirmed that this issue was resolved in Unity 2021.2b14. Now you can use the package with both the .NET Standard and .NET Framework profiles. Although the HDRP issue (wrong dependency to System.Memory from the Searcher package) still exists, it will be solved on the HDRP side. So I close this issue now.

Please feel free to reopen it if it reproduces on 2021.2b14 or later versions.