keijiro / Lasp

Low-latency Audio Signal Processing plugin for Unity
The Unlicense
1.56k stars 119 forks source link

The type or namespace name 'Span<>' could not be found #28

Open MateiGiurgiu opened 4 years ago

MateiGiurgiu commented 4 years ago

I get this error when I import the package. I mention that I am using the package manager for this as described in the readme. The weird thing is that a couple a days ago I managed to import this into an empty project and it worked. I tried deleting the cache, switching the scripting backend. Importing System.Memory from NuGet but nothing seems to be able to fix it.

Do you have any idea what might be the cause?

Using Unity 2019.3.15f1 and Visual Studio 2019

image

MateiGiurgiu commented 4 years ago

I just went back to the empty project where LASP imported successfully and I realized that as soon as I right-click > Open C# project, the error appears.

Additionally, I added the System.Memory.dll in the Plugins folder and now the error that I have is: image

I also enabled "Allow 'unsafe' code" option in player setting but it didn't help.

MateiGiurgiu commented 4 years ago

I did more testing today. In the empty project where LASP initially imported successfully, I managed to get rid of the errors by reimporting the project. However, I realized that the error is caused by a third party plugin called Quantum Console. As soon as I imported it the exact error appeared again and I couldn't do anything to make it disappear.

Ryne9 commented 4 years ago

Seeing the same issue on 2019.3.10f1 with the ReadOnlySpan in ChannelLayout and the Spans in Device.

keijiro commented 4 years ago

@Ryne9 Are you using Quantum Console too?

Ryne9 commented 4 years ago

Nope, two biggest libraries I'm using are UniVRM and TwitchLib, I can test adding them to a new project tomorrow and seeing what happens.

keijiro commented 4 years ago

@Ryne9 Thanks for the additional info. I'd appreciate if you could check which one causes the error.

Ryne9 commented 4 years ago

Ah, I think it is directly related to setting the Project Settings > Player > Other Settings > Configuration > Api Compatibility Level from .NET Standard 2.0 to .NET 4.x

apicompat

MateiGiurgiu commented 4 years ago

Thank you. However, I was already on .NET 4.x and I tested it with both compatibility levels and scripting backends.

I noticed that Quantum Console comes with a link.xml file which from my understanding is used for configuring how the code is stripped. Could this be the cause of the problem? image

MateiGiurgiu commented 4 years ago

I did more testing. I managed to successfully import both LASP and Quantum Console in the same project as long as initially the project is set to .NET Standard 2.0. As soon as I move it back to .NET 4.x I get errors: image

image

Moreover, I imported LASP into another empty project set to .NET Standard 2.0 and as soon as I switch to .NET 4.x the errors appeared again.

keijiro commented 4 years ago

@MateiGiurgiu Thank you very much for further testing. It seems that there is something wrong with the API compatibility setting. Actually, I only tested LASP with the .NET Standard 2.0. I'll do extensive tests with .NET 4.x for the next version of LASP.

Just out of curiosity, do you need .NET 4.x for your project? I have never used .NET 4.x on my projects, so I overlooked the point.

Ryne9 commented 4 years ago

Personally I've never needed to change API compatibility until I wanted a Twitch library so I used TwitchLib.Unity which required it. After this issue I did think of rewriting/investigating since Lasp is way more important for my project at the moment

keijiro commented 4 years ago

Twitch requires .NET 4.x. Okay. That's a valuable input. Thanks.

MateiGiurgiu commented 4 years ago

My thoughts are on the same lines as @Ryne9. I don't need .NET 4.x in the project at the moment. When I got LASP, the only reason I wanted to see if it works properly on both compatibility levels was that the project is in early development and I might need some plugins in the future which may require 4.x and I didn't want to have problems at that point.

Long story short I am developing an audio visualizer app and at the moment I implemented a custom system to process the audio signal (taken using NAudio) using FFT in order to generate the spectrum. Then I discovered LASP which seems way more attractive due to low-latency and normalization features among others. Therefore, I prefer to stick with .NET Standard 2.0 if LASP will become a core component of the project.

Is LASP using the libsoundio wrapper that you wrote? And, if yes, does that mean that LASP only supports 64bit systems?

keijiro commented 4 years ago

Is LASP using the libsoundio wrapper that you wrote? And, if yes, does that mean that LASP only supports 64bit systems?

Yes, it only supports x64 at the moment.

MateiGiurgiu commented 4 years ago

@keijiro I just found a limitation of .NET Standard 2.0. I was trying to make a windows native file browser dialog and I require System.Windows.Forms.dll. I made a file csc.rsp and added: "-r:System.Windows.Forms.dll". However, this works only with .NET 4.x.

melMass commented 3 years ago

Unsafe should work as long as your project settings (or asmdef) "allow for unsafe code" which is unchecked in your case

marcospgp commented 3 years ago

Got this error and fixed it by setting the API compatibility level to .NET Standard 2.0 as mentioned above:

image

Though I am not quite clear on the difference between the two options. From what I've read, setting the compatibility level to .NET 4.x should not remove support for any feature, only increasing the available API surface.

Maybe Span<T> is a newer feature and unique in being supported only by .NET Standard 2.0?

Anyway it could be useful to add this info to the readme 🙂

Nolram12345 commented 3 years ago

+1 this issue, Net 4.x is now often required by various other tools.

Nolram12345 commented 3 years ago

grafik Even after switching to 2.0 I still get this error.

keijiro commented 3 years ago

@marcospgp

From what I've read, setting the compatibility level to .NET 4.x should not remove support for any feature, only increasing the available API surface.

No. Those documents are written in the .NET 3.5 era so has been outdated. Now, NET Standard 2.0 is the recommended option in general cases.

Maybe Span is a newer feature and unique in being supported only by .NET Standard 2.0?

Actually, that's a new feature in .NET Standard 2.1. We can use it on .NET Standard 2.0 by adding the nuget package.

keijiro commented 3 years ago

@Nolram12345

Net 4.x is now often required by various other tools.

Could you give me an example? I'm curious about the reasons why .NET 4.x is still used in some cases.

Even after switching to 2.0 I still get this error.

This error message is not related to LASP. Please try removing other unrelated packages.

keijiro commented 3 years ago

@marcospgp Sorry. The first paragraph in the last reply might be not correct. I should admit that I'm not a .NET specialist. Please ask a specialist for further details.

keijiro commented 3 years ago

Note that there is the same issue in KlakNDI.

https://github.com/keijiro/KlakNDI/issues/72

The conclusion here is the same to KlakNDI. There is no plan for fixing it, but this issue should be kept opened for future reference.

Nolram12345 commented 3 years ago

@keijiro A json data storing tool I am using requires .NET framework which is only supported in 4.x . And I am unsure what exactly you mean since in the error it states that a namespace is missing from LASP - and the script that is asking for it is from Klak Audio. (Which is the reason I am trying to install LASP in the first place).

keijiro commented 3 years ago

@Nolram12345 If you're using KlakLasp, it's not compatible with the current version of LASP.

Nolram12345 commented 3 years ago

@keijiro Then what version do I need ? Is it even still supported/does it still work ?

keijiro commented 3 years ago

@Nolram12345

Lasp v1 is still in the master branch.

https://github.com/keijiro/Lasp/tree/master

I haven't been touched it for some years, so I'm not sure if it still works.

Please use the issue tracker on the KlakLasp repository for further questions. It's not relevant to the original question in this thread.

Nolram12345 commented 3 years ago

@keijiro Sure. Thank you.

ChiefBreakeverything commented 3 years ago

Unfortunately I'm also in the same boat. I'm getting this Span<> error on import and I'm trying some stuff out with Arduino depth sensors (or Kinect as a backup) but it seems that both require .Net 4.x. I'm really keen to try Lasp out though...

hnguyen094 commented 3 years ago

I think the issue is with the NuGet package dependencies (e.g. org.nuget.system.memory). Specifically, they have a "Define Constraint" NET_STANDARD_2_0 which isn't defined when targeting .NET 4.x (whether that's the correct behavior or not I'm not sure.)

The 'correct' solution is either to target .NET Standard 2.0, or (probably) manually include the correct .NET 4.x System.Memory.dll (and possibly its other dependencies that don't have the Define Constraint) by adding it to your project. Alternatively, @keijiro can maybe find another package dependency that don't have this define constraint.

Here's an 'incorrect' solution though: you might be able to get away with adding NET_STANDARD_2_0 to Scripting Define Symbols while still targeting .NET 4.x. I just tested this hack and it seems to work on 2020.3.1 (Mono .NET 4.x)

keijiro commented 3 years ago

@hnguyen094 Thanks for the write-up. That matches with my understanding.

visible-sounds commented 2 years ago

Had the same issue with both 2.0 and 4x for some reason.

Not sure if it makes much difference as Unity apparently doesn't use .NET 2.1 yet however I downloaded and installed .NET core 2.1

The solution for me was to directly download the dll for Span.

1) You can get the library from the https://www.nuget.org/packages/System.Memory/ => Download Package 2) Open it with WinRAR or similar. 3) Import the System.Memory.dll from lib/netstandartd2.0 folder into your assets folder.

4) Select System.Memory.dll in the editor, go to import settings in the inspect then Disable "Validate Reference"

After I did that I had error finding reference to Unsafe so did the same with the Unsafe package. Maybe not required for some people 5) https://www.nuget.org/packages/System.Runtime.CompilerServices.Unsafe/ Repeat steps 2 to 4 for this package.

Answer taken from and changed slightly by me, hope this helps someone :) https://stackoverflow.com/questions/56885284/implement-spant-in-unity

judasbenhur commented 2 years ago

adding the following lines to the manifest.json fixed this issue for me in klakNDI.

"scopedRegistries": [ { "name": "Unity NuGet", "url": "https://unitynuget-registry.azurewebsites.net", "scopes": [ "org.nuget" ] } ],

and then inside the '"dependencies": {' bracket: "org.nuget.system.memory": "4.5.3"

hope this helps.

atesija commented 2 years ago

I ran into this on version 2020.3.14f1 even when using .NET Standard 2.0. Switched to 2019.4.0f1 instead and I'm able to use the library with no errors.

prakyath-07 commented 2 years ago

Add these to manifest file "org.nuget.system.memory": "4.5.3"

"scopedRegistries": [ { "name": "Unity NuGet", "url": "https://unitynuget-registry.azurewebsites.net", "scopes": [ "org.nuget" ] } ]

PatrickkLiu commented 1 year ago

Here's an 'incorrect' solution though: you might be able to get away with adding NET_STANDARD_2_0 to Scripting Define Symbols while still targeting .NET 4.x. I just tested this hack and it seems to work on 2020.3.1 (Mono .NET 4.x)

the 'incorrect' solution worked for me after I switched to IL2CPP backend on 2019.4.6. Hope this helps!