Unity 2019.2 background exception when socket connects

We’re trying to solve a mysterious lockup when we first initialize Nakama. We’re using 2.8.0, Unity 2019.2.14f1, and Unity Nakama SDK 2.3.2. We noticed this exception when we call:

await socket.ConnectAsync(session);

12-04 21:28:08.798 21371 21413 D Unity : Unable to lookup library path for ‘advapi32’, native render plugin support disabled.
12-04 21:28:08.799 21371 21413 E Unity : Unable to find advapi32
12-04 21:28:08.809 21371 21413 W Unity : Plugins: Couldn’t open advapi32, error: dlopen failed: library “advapi32” not found

Any ideas about this error and possible solutions? Thanks.

I’ve never seen that dll error. I think it might be related to a bad Unity installation. Can you do a fresh re-install and try again?

sure we can try that, will report back.

we’ve tried with 5f1 and 14f1 and we’re getting that exception on both versions. Our production CI builds are also throwing the exception so it seems it’s not related to the unity install.
Here’s the full stack:
12-05 17:26:20.960 3140 3183 E Unity : Unable to find advapi32
12-05 17:26:20.973 3140 3183 W Unity : Plugins: Couldn’t open advapi32, error: dlopen failed: library “advapi32” not found
12-05 17:26:20.973 3140 3183 W Unity : Microsoft.Win32.ManifestEtw:EventRegister(Guid&, EtwEnableCallback, Void*, Int64&)
12-05 17:26:20.973 3140 3183 W Unity : System.Diagnostics.Tracing.EventProvider:Register(Guid)
12-05 17:26:20.973 3140 3183 W Unity : System.Diagnostics.Tracing.EventSource:Initialize(Guid, String, String)
12-05 17:26:20.973 3140 3183 W Unity : System.Diagnostics.Tracing.EventSource:.ctor(EventSourceSettings, String)
12-05 17:26:20.973 3140 3183 W Unity : Nakama.Ninja.WebSockets.Internal.Events:.cctor()
12-05 17:26:20.973 3140 3183 W Unity : Nakama.Ninja.WebSockets.WebSocketClientOptions:.ctor()
12-05 17:26:20.973 3140 3183 W Unity : Nakama.Ninja.WebSockets.Internal.Events:.cctor()
12-05 17:26:20.973 3140 3183 W Unity : Nakama.Ninja.WebSockets.WebSocketClientFactory:GetStream(Guid, Boolean, Boolean, String, Int32, CancellationToken)
12-05 17:26:20.973 3140 3183 W Unity : Nakama.Ninja.WebSockets.WebSocketClientOptions:.ctor()
12-05 17:26:20.973 3140 3183 W Unity : Nakama.Ninja.WebSockets.Internal.Events:.cctor()
12-05 17:26:20.973 3140 3183 W Unity : Nakama.Ninja.WebSockets.WebSocketClientFactory:ConnectAsync(Uri, WebSocketClientOptions, CancellationToken)
12-05 17:26:20.973 3140 3183 W Unity : Nakama.WebSocketAdapter:ReadFrames(WebSocketReceiveResult, WebSocket, Byte)
12-05 17:26:20.973 3140 3183 W Unity : Nakama.ApiClient:ListUserGroupsAsync(String, String, Nullable1, Nullable1, String)

@oscargoldman This issue is not related to the Nakama Unity client sdk at all. I think you’ll have more luck with this issue on the Unity forums.

I’m getting the same error here, at initialization.
I think it’s due to some Nakama dll dependency, I’ve never encounter this problem with Unity before

We are using Nakama 2.8.0, Unity 2019.2.10f1, and Unity Nakama Client SDK 2.3.2

@danim and @oscargoldman which .NET API compatibility level have you both set in your Unity 2019 projects?

2.0 and 4.X I’ve tried both, and the initialization exception is there :frowning:

Ok I have two ideas that could resolve the issue but I will need your help to try them @danim. I’ll share two different builds of the client sdk for you to try. Will you have time to help with it?

Of course! Glad to help

@danim Please could you try this build and let me know if it works on device and which devices you’ve tested on with Android and iOS.

Nakama-361build.unitypackage.txt (106.8 KB)

NOTE: You should rename the file extension to ".unitypackage". I’ve renamed it because the forum does not understand non-standard file extensions and rejects the upload.

I’ve tested it on Android and it’s still happening sorry.
Now the message Plugins: Couldn't open advapi32, error: dlopen failed: library "advapi32" not found is printed twice.

Ok. Thanks @danim. I’ll prepare another build for you to use. This one will work although I believe that the problem lies with how Unity have changed what .NET libraries are made available as part of their standard distribution. :confused:

@danim Please can you try this build. If this does not work I’ve got one more build you can try which I’m sure will work.

Nakama-361build2.unitypackage.txt (106.8 KB)

Still happening, sorry.
It happens the first time I call ConnectAsync(m_session, true);. If I don’t open any socket, the error is gone.
I can continue playing, but that warning it’s just weird.

Thanks for all the help @danim. Last time please can you try this build:

Nakama-361build3.unitypackage.txt (113.8 KB)

Sorry for the delay.
The error is gone!

No worries. Thanks a lot for the help @danim :+1:

I know what has happened and will explain in detail so it helps us resolve the issue faster next time. :slight_smile:

It appears that in Unity 2019.2 and above Unity have changed the default .NET profile. A .NET profile describes to the Roslyn compiler toolchain what collection of DLLs are available from the standard library. I don’t know whether this change was intended by them or a bug in the latest release of the game engine. It’s unclear from their release notes or online resources why they’ve made this change.

The result of it is that the System.Diagnostics.Tracing namespace is no longer available in the .NET profile which Unity uses. This affects how we trace the low level details in the socket libraries we use. The only solution I’ve found which resolves the issue fully so far is to strip out usages of that namespace. I’ll have to dig further in the new year to understand whether the change that Unity has made was intentional.

1 Like

I am getting this same issue.
Not sure if it is related but It might be related with https://issuetracker.unity3d.com/issues/unable-to-load-dll-advapi32-dot-dll-when-calling-datetime-dot-now

@iabhipatidar Have you tried this Unity package I put together?