Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implement Span<T> in Unity

I'm trying to use Span in Unity.

I understand that System.Memory is not supported yet, but I'd like to implement it anyway.

I directly downloaded the library from NuGet. I got the System.Memory.dll from netstandard2.0 folder in the nuget package and dragged it in the project Assets/Scripts folder.

But I get this error, and I cannot use it in my IDE (Rider).

Assembly 'Assets/System.Memory.dll' will not be loaded due to errors: Unable to resolve reference 'System.Runtime.CompilerServices.Unsafe'. Is the assembly missing or incompatible with the current platform?

My question is: how can I use Span in Unity?


Unity Version: Unity 2019.1.7f.
OS: Windows

like image 991
Jack Mariani Avatar asked Aug 08 '26 18:08

Jack Mariani


1 Answers

Nuget may generate issues in Unity.

The solution is to directly download the dll.

  1. Get the library from the direct download => Download Package

  2. Import the System.Memory.dll from lib/netstandartd2.0 folder into the Project Window

  3. Select System.Memory.dll in the Project Window then Disable "Validate Reference"

enter image description here

I took the info from unity forum and applied to my situation. (In the forum they are using Unity Packages, while I'm just setting the library on the Assets)

like image 196
Jack Mariani Avatar answered Aug 11 '26 09:08

Jack Mariani



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!