Hi, i’m looking for help trying to figure Unity / .NET compatibility.
What i understand from official documentation is that Unity 2019/2020 supports .NET standard 2.0 and .NET Framework 4.x, with .NET standard 2.0 being the suggested one to use. Seems clear to me that neither .NET Core nor .NET 5+ are supported in Unity 2019 or 2020.
Recently, i stumbled upon an issue that brought to my attention that some “ReadOnlySpan” is used in the project i’m working on. Looking into msdn docs, i clearly see that ReadOnlySpan is available in .Net standard 2.1, .Net Core or .NET 5>. This API is bundled in the System.Memory assembly DLL: if i simply put this DLL into Unity, i can use the API no problem building with IL2CPP or in the editor through Mono…my question is how is that possible, given the fact that we are dealing with an API that should not be supported by Unity?
Maybe this’ll answer some of your questions. Note that 2019 and 2020 are older versions of Unity; features are never backported, only bug fixes.
Thanks, it’s clear to me that 2019 and 2020 are older versions. That’s why i asked about that very example that i came across because it seems to me that, given all the information about what should and shouldn’t work with .NET, still i don’t understand why it’s working.
Hope some other can jump in and elaborate.
There are versions of System.Memory.dll that will work with .NET Standard 2.0, so I suspect that is what is happening. If you using Unity 2021.2 and later, which supports .NET Standard 2.1, you can use a “better” version of the Span<> types, as the runtime has more intimate knowledge of them and can optimize them better.
Thank you Josh and Melv, i think i’m starting to have a grasp of what’s happening. The System.Memory.dll is in fact generated by the ‘publish’ action done in our .Net Standard 2.0 project (outside of Unity), so the final artifacts are the specific dlls of our project plus all the necessary dependencies dlls, like the System.Memory one, which all are built using Net standard 2.0 profile. Those dlls are then imported into Unity and used from scripts inside our Unity project so no surprises here, should be legitimate in Unity 2019/2020 too.
What is still baffling to me is that ReadOnlySpan is not in .NET Standard 2.0, but only from 2.1
but from Unity i can still use the API from a dll build against Net Standard 2.0 profile
I suspect that the project is using the System.Memory.dll from NuGet that is compatible with .NET Standard 2.0: https://www.nuget.org/packages/System.Memory/
You are very right indeed, System.Memory is the only Nuget dep in the project, thanks!