Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Api Compatibility Level .Net 4.x problem #72

Closed
sasa42 opened this issue Jul 12, 2020 · 33 comments
Closed

Api Compatibility Level .Net 4.x problem #72

sasa42 opened this issue Jul 12, 2020 · 33 comments
Assignees
Labels
question Further information is requested

Comments

@sasa42
Copy link

sasa42 commented Jul 12, 2020

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 keijiro self-assigned this Jul 12, 2020
@keijiro keijiro added the question Further information is requested label Jul 12, 2020
@keijiro
Copy link
Owner

keijiro commented Jul 12, 2020

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

keijiro/Lasp#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
Copy link
Author

sasa42 commented Jul 12, 2020

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
Copy link
Author

sasa42 commented Jul 12, 2020

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
Copy link
Author

sasa42 commented Jul 12, 2020

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/[email protected]",
"org.nuget.system.memory": "file:../LocalPackages/[email protected]"
}
}

@sasa42
Copy link
Author

sasa42 commented Jul 12, 2020

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
Copy link
Owner

keijiro commented Jul 13, 2020

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
Copy link
Author

sasa42 commented Jul 13, 2020

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
Copy link

ToxMox commented Jul 30, 2020

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
Copy link
Owner

keijiro commented Jul 31, 2020

@ToxMox Did you try the NET_STANDARD_2_0 workaround?

#72 (comment)

@ToxMox
Copy link

ToxMox commented Jul 31, 2020

@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
Copy link
Owner

keijiro commented Jul 31, 2020

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? #72 (comment)

@ToxMox
Copy link

ToxMox commented Jul 31, 2020

@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
Copy link

ToxMox commented Aug 2, 2020

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
Copy link

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

@Soaryn
Copy link

Soaryn commented Aug 10, 2020

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
Copy link

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
Copy link

Sampoman commented Nov 5, 2020

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
Copy link
Owner

keijiro commented Nov 6, 2020

@Sampoman It seems that the UnityNuGet registry has a problem. I reported it to the author. xoofx/UnityNuGet#17

@keijiro
Copy link
Owner

keijiro commented Nov 6, 2020

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

@v2k
Copy link

v2k commented Nov 17, 2020

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
Copy link
Owner

keijiro commented Nov 17, 2020

@v2k I'd recommend defining NET_STANDARD_2_0. See: #72 (comment)

@v2k
Copy link

v2k commented Nov 17, 2020

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
Copy link

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

@keijiro
Copy link
Owner

keijiro commented Nov 23, 2020

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

@hybridherbst
Copy link

hybridherbst commented Nov 23, 2020

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
Copy link

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
Copy link

xoofx commented Dec 2, 2020

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
Copy link
Owner

keijiro commented Dec 3, 2020

@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
Copy link

@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
Copy link
Owner

keijiro commented Dec 4, 2020

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

@keijiro
Copy link
Owner

keijiro commented Dec 4, 2020

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
Copy link
Owner

keijiro commented Sep 22, 2021

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
Copy link
Owner

keijiro commented Oct 2, 2021

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.

@keijiro keijiro closed this as completed Oct 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests