# Unity 2019.2 background exception when socket connects

**URL:** <https://forum.heroiclabs.com/t/unity-2019-2-background-exception-when-socket-connects/361>\
**Category:** Local Setup\
**Created:** [December 5, 2019, 2:49pm UTC](https://forum.heroiclabs.com/t/unity-2019-2-background-exception-when-socket-connects/361 "2019-12-05T14:49:37Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![oscargoldman](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/oscargoldman/32/28_2.png) [@oscargoldman](https://forum.heroiclabs.com/u/oscargoldman)\
**Post date:** [December 5, 2019, 2:49pm UTC](https://forum.heroiclabs.com/t/unity-2019-2-background-exception-when-socket-connects/361/1 "2019-12-05T14:49:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mofirouz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/mofirouz/32/1523_2.png) [@mofirouz](https://forum.heroiclabs.com/u/mofirouz)\
**Post date:** [December 5, 2019, 3:12pm UTC](https://forum.heroiclabs.com/t/unity-2019-2-background-exception-when-socket-connects/361/2 "2019-12-05T15:12:07Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![oscargoldman](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/oscargoldman/32/28_2.png) [@oscargoldman](https://forum.heroiclabs.com/u/oscargoldman)\
**Post date:** [December 5, 2019, 3:13pm UTC](https://forum.heroiclabs.com/t/unity-2019-2-background-exception-when-socket-connects/361/3 "2019-12-05T15:13:16Z")

</div>

sure we can try that, will report back.

---

<div class="post-metadata">

**Author:** ![oscargoldman](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/oscargoldman/32/28_2.png) [@oscargoldman](https://forum.heroiclabs.com/u/oscargoldman)\
**Post date:** [December 5, 2019, 5:03pm UTC](https://forum.heroiclabs.com/t/unity-2019-2-background-exception-when-socket-connects/361/4 "2019-12-05T17:03:10Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![novabyte](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/novabyte/32/1324_2.png) [@novabyte](https://forum.heroiclabs.com/u/novabyte)\
**Post date:** [December 5, 2019, 5:48pm UTC](https://forum.heroiclabs.com/t/unity-2019-2-background-exception-when-socket-connects/361/5 "2019-12-05T17:48:12Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![danim](https://avatars.discourse-cdn.com/v4/letter/d/c57346/32.png) [@danim](https://forum.heroiclabs.com/u/danim)\
**Post date:** [December 10, 2019, 1:47pm UTC](https://forum.heroiclabs.com/t/unity-2019-2-background-exception-when-socket-connects/361/6 "2019-12-10T13:47:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![novabyte](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/novabyte/32/1324_2.png) [@novabyte](https://forum.heroiclabs.com/u/novabyte)\
**Post date:** [December 11, 2019, 9:52am UTC](https://forum.heroiclabs.com/t/unity-2019-2-background-exception-when-socket-connects/361/7 "2019-12-11T09:52:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![danim](https://avatars.discourse-cdn.com/v4/letter/d/c57346/32.png) [@danim](https://forum.heroiclabs.com/u/danim)\
**Post date:** [December 11, 2019, 10:28am UTC](https://forum.heroiclabs.com/t/unity-2019-2-background-exception-when-socket-connects/361/8 "2019-12-11T10:28:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![novabyte](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/novabyte/32/1324_2.png) [@novabyte](https://forum.heroiclabs.com/u/novabyte)\
**Post date:** [December 11, 2019, 10:58am UTC](https://forum.heroiclabs.com/t/unity-2019-2-background-exception-when-socket-connects/361/9 "2019-12-11T10:58:59Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![danim](https://avatars.discourse-cdn.com/v4/letter/d/c57346/32.png) [@danim](https://forum.heroiclabs.com/u/danim)\
**Post date:** [December 11, 2019, 11:43am UTC](https://forum.heroiclabs.com/t/unity-2019-2-background-exception-when-socket-connects/361/10 "2019-12-11T11:43:55Z")

</div>

Of course! Glad to help

---

<div class="post-metadata">

**Author:** ![novabyte](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/novabyte/32/1324_2.png) [@novabyte](https://forum.heroiclabs.com/u/novabyte)\
**Post date:** [December 11, 2019, 2:11pm UTC](https://forum.heroiclabs.com/t/unity-2019-2-background-exception-when-socket-connects/361/11 "2019-12-11T14:11:51Z")

</div>

@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](https://forum.heroiclabs.com/uploads/short-url/7P8WGIPPDq5VOlz8NeTCw2m7ZF4.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.

---

<div class="post-metadata">

**Author:** ![danim](https://avatars.discourse-cdn.com/v4/letter/d/c57346/32.png) [@danim](https://forum.heroiclabs.com/u/danim)\
**Post date:** [December 11, 2019, 3:35pm UTC](https://forum.heroiclabs.com/t/unity-2019-2-background-exception-when-socket-connects/361/12 "2019-12-11T15:35:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![novabyte](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/novabyte/32/1324_2.png) [@novabyte](https://forum.heroiclabs.com/u/novabyte)\
**Post date:** [December 11, 2019, 7:53pm UTC](https://forum.heroiclabs.com/t/unity-2019-2-background-exception-when-socket-connects/361/13 "2019-12-11T19:53:28Z")

</div>

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. 😕

---

<div class="post-metadata">

**Author:** ![novabyte](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/novabyte/32/1324_2.png) [@novabyte](https://forum.heroiclabs.com/u/novabyte)\
**Post date:** [December 12, 2019, 10:02am UTC](https://forum.heroiclabs.com/t/unity-2019-2-background-exception-when-socket-connects/361/14 "2019-12-12T10:02:15Z")

</div>

@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](https://forum.heroiclabs.com/uploads/short-url/7bKsk2ti3EXjWsqS7XGW2YOHBPM.txt) (106.8 KB)

---

<div class="post-metadata">

**Author:** ![danim](https://avatars.discourse-cdn.com/v4/letter/d/c57346/32.png) [@danim](https://forum.heroiclabs.com/u/danim)\
**Post date:** [December 12, 2019, 11:57am UTC](https://forum.heroiclabs.com/t/unity-2019-2-background-exception-when-socket-connects/361/15 "2019-12-12T11:57:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![novabyte](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/novabyte/32/1324_2.png) [@novabyte](https://forum.heroiclabs.com/u/novabyte)\
**Post date:** [December 12, 2019, 8:02pm UTC](https://forum.heroiclabs.com/t/unity-2019-2-background-exception-when-socket-connects/361/16 "2019-12-12T20:02:52Z")

</div>

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

[Nakama-361build3.unitypackage.txt](https://forum.heroiclabs.com/uploads/short-url/qubANenJTnKyydUVU6pjfIcOKwp.txt) (113.8 KB)

---

<div class="post-metadata">

**Author:** ![danim](https://avatars.discourse-cdn.com/v4/letter/d/c57346/32.png) [@danim](https://forum.heroiclabs.com/u/danim)\
**Post date:** [December 17, 2019, 8:21am UTC](https://forum.heroiclabs.com/t/unity-2019-2-background-exception-when-socket-connects/361/17 "2019-12-17T08:21:38Z")

</div>

Sorry for the delay.  
The error is gone!

---

<div class="post-metadata">

**Author:** ![novabyte](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/novabyte/32/1324_2.png) [@novabyte](https://forum.heroiclabs.com/u/novabyte)\
**Post date:** [December 17, 2019, 10:58am UTC](https://forum.heroiclabs.com/t/unity-2019-2-background-exception-when-socket-connects/361/18 "2019-12-17T10:58:36Z")

</div>

No worries. Thanks a lot for the help @danim 👍

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

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.

---

<div class="post-metadata">

**Author:** ![iabhipatidar](https://avatars.discourse-cdn.com/v4/letter/i/b4bc9f/32.png) [@iabhipatidar](https://forum.heroiclabs.com/u/iabhipatidar)\
**Post date:** [January 13, 2020, 7:40am UTC](https://forum.heroiclabs.com/t/unity-2019-2-background-exception-when-socket-connects/361/19 "2020-01-13T07:40:12Z")

</div>

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](https://issuetracker.unity3d.com/issues/unable-to-load-dll-advapi32-dot-dll-when-calling-datetime-dot-now)

---

<div class="post-metadata">

**Author:** ![novabyte](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/novabyte/32/1324_2.png) [@novabyte](https://forum.heroiclabs.com/u/novabyte)\
**Post date:** [January 13, 2020, 10:12am UTC](https://forum.heroiclabs.com/t/unity-2019-2-background-exception-when-socket-connects/361/20 "2020-01-13T10:12:56Z")

</div>

> [@novabyte](#):
>
> Thanks for all the help @danim. Last time please can you try this build:
> 
> [Nakama-361build3.unitypackage.txt](https://forum.heroiclabs.com/uploads/short-url/qubANenJTnKyydUVU6pjfIcOKwp.txt) (113.8 KB)

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

[Next page](https://forum.heroiclabs.com/t/unity-2019-2-background-exception-when-socket-connects/361.md?page=2)
