32feet icon indicating copy to clipboard operation
32feet copied to clipboard

PlatformNotSupportedException and System.DllNotFoundException: ws2_32.dll in 4.0.29

Open Adrien-pierret opened this issue 2 years ago • 4 comments

Hello everyone,

While trying to build and/or run the projects I ran into 2 distinct issues: ・If I run the project using .NET Standard 2.0 I get a "PlatformNotSupportedException" ・If I change and run it with .NET 4.x I get a "System.DllNotFoundException: ws2_32.dll" and a "System.Windows.Forms.dll assembly is referenced by user code, but is not supported on Android platform. Various failures might follow." warning.

Both errors occur for the "InTheHand.Net.Bluetooth 4.0.29" package when i try to execute: BluetoothClient client = new BluetoothClient(); And they both happen on the phone and on the simulation.

Other info: ・I am running Unity 2020.3.33f1 ・OS: Ubuntu 20.04 ・Target: Android (Google pixel 4) ・The package was installed using Nuget for Unity

Best regards

Adrien-pierret avatar Apr 26 '22 09:04 Adrien-pierret

I think the way that Unity manages NuGet platforms is different to Visual Studio which leads it to select the wrong dll. There is a monoandroid dll in the package which should work. You could try extracting it manually and referencing it directly. The .NET 4 dll is for Windows only hence the ws2_32.dll error, the .NET Standard dll has no implementation and simply acts as an API surface to be replaced with the correct runtime version. I will need to do some more testing with Unity to work out a fix.

peterfoot avatar Apr 26 '22 09:04 peterfoot

Thank you peter for such a quick answer. So I gave it a try and downloaded the package from "https://www.nuget.org/packages/InTheHand.Net.Bluetooth" I just took the dll from the monoandroid11 folder and added it to my plugins and Assets/Packages (not at the same time, on 2 different occasions). Now when I try to build I run into the following:

"ArgumentException: The Assembly Mono.Android is referenced by InTheHand.Net.Bluetooth ('Assets/Plugins/inthehand.net.bluetooth.4.0.29/InTheHand.Net.Bluetooth.dll'). But the dll is not allowed to be included or could not be found."

I tried to compile for Android 10; 11 and "highest available" in Unity. I Also tried both .NET 2.0 and 4.X. Same result. Am I missing something?

p.s: I am new to Unity and C# so I might have done something wrong. Sorry if I made some newbies mistakes.

Adrien-pierret avatar Apr 26 '22 10:04 Adrien-pierret

I'm not a native to Unity either so don't know my way around all the differences with a regular .NET project. I've used it previously to test the Windows version of the dll, but not Android but it should work. I'll do some investigation...

peterfoot avatar Apr 27 '22 10:04 peterfoot

I have the same problem, here's the environment I used, ・Unity 2022.3.16f1 ・Dev OS: Windows 11 Home ・Target: Android (Google Pixel 7a) ・Package was installed using NuGet for Unity

I tried to do what @Adrien-pierret did, by manually extracting the "monoandroid10" dlls into the package. I got the following error, which is slightly different from the one @Adrien-pierret mentioned,

Assembly 'Assets/Packages/InTheHand.Net.Bluetooth.4.1.40/lib/monoandroid10/InTheHand.Net.Bluetooth.dll' will not be loaded due to errors: Unable to resolve reference 'Mono.Android'. Is the assembly missing or incompatible with the current platform?

~Is there a solution or a possible workaround for this?~

It turns out that Mono.Android only exists in Xamarin.Forms. Unity seems to be using something different (for Android, at least), hence it is unable to find Mono.Android explicitly. I don't think using monoandroid10's dlls will work with Unity for now.

Meanwhile if you use the net461 dlls instead, you get "System.DllNotFoundException: ws2_32.dll" that doesn't exist in Android platforms.

It seems that 32feet is not compatible with Unity-Android implementations for now, unless there is some way to reference Unity's Android components

NicholasLimHongDa avatar Feb 02 '24 04:02 NicholasLimHongDa