Realm .net sdk (10.0.0-beta.3) crashes on launch

Hello,

I’m currently trying to test out realm for my next project. I’ve created a very basic console app using .net framework 5.0.102 and realm nuget package (10.0.0-beta.3). Unfortunately right from the start:

var app = App.Create("foo");

I’m getting an exception:

TypeInitializationException: The type initializer for ‘Realms.Sync.AppHandle’ threw an exception.
Inner Exception 2:
DllNotFoundException: Unable to load DLL ‘realm-wrappers’ or one of its dependencies: The specified module could not be found. (0x8007007E)

IDE:
Microsoft Visual Studio Community 2019
Version 16.8.4

Any ideas how to fix this? I do see wrappes being available in ‘runtimes’ folder:

λ dir /s
 Volume in drive C has no label.
 Volume Serial Number is C2FB-E58D

 Directory of ..\bin\Debug\net5.0

01/18/2021  03:21 PM    <DIR>          .
01/18/2021  03:21 PM    <DIR>          ..
10/15/2020  08:23 PM           466,944 MongoDB.Bson.dll
12/10/2020  01:41 PM           305,152 Realm.dll
01/18/2021  03:10 PM            22,841 Realm_POC.deps.json
01/18/2021  03:10 PM            12,288 Realm_POC.dll
01/18/2021  03:10 PM           142,848 Realm_POC.exe
01/18/2021  03:10 PM            10,780 Realm_POC.pdb
01/18/2021  03:10 PM               246 Realm_POC.runtimeconfig.dev.json
01/18/2021  03:10 PM               147 Realm_POC.runtimeconfig.json
01/15/2021  07:07 PM    <DIR>          ref
02/14/2019  03:21 PM           176,640 Remotion.Linq.dll
01/15/2021  07:07 PM    <DIR>          runtimes
               9 File(s)      1,137,886 bytes

 Directory of ..\bin\Debug\net5.0\ref

01/15/2021  07:07 PM    <DIR>          .
01/15/2021  07:07 PM    <DIR>          ..
01/15/2021  07:07 PM             6,656 Realm_POC.dll
               1 File(s)          6,656 bytes

 Directory of ..\bin\Debug\net5.0\runtimes

01/15/2021  07:07 PM    <DIR>          .
01/15/2021  07:07 PM    <DIR>          ..
01/15/2021  07:07 PM    <DIR>          linux-x64
01/15/2021  07:07 PM    <DIR>          osx-x64
01/15/2021  07:07 PM    <DIR>          win-x64
01/15/2021  07:07 PM    <DIR>          win-x86
               0 File(s)              0 bytes

 Directory of ..\bin\Debug\net5.0\runtimes\linux-x64

01/15/2021  07:07 PM    <DIR>          .
01/15/2021  07:07 PM    <DIR>          ..
01/15/2021  07:07 PM    <DIR>          native
               0 File(s)              0 bytes

 Directory of ..\bin\Debug\net5.0\runtimes\linux-x64\native

01/15/2021  07:07 PM    <DIR>          .
01/15/2021  07:07 PM    <DIR>          ..
12/10/2020  01:40 PM        15,529,368 librealm-wrappers.so
               1 File(s)     15,529,368 bytes

 Directory of ..\bin\Debug\net5.0\runtimes\osx-x64

01/15/2021  07:07 PM    <DIR>          .
01/15/2021  07:07 PM    <DIR>          ..
01/15/2021  07:07 PM    <DIR>          native
               0 File(s)              0 bytes

 Directory of ..\bin\Debug\net5.0\runtimes\osx-x64\native

01/15/2021  07:07 PM    <DIR>          .
01/15/2021  07:07 PM    <DIR>          ..
12/10/2020  01:33 PM        13,133,840 librealm-wrappers.dylib
               1 File(s)     13,133,840 bytes

 Directory of ..\bin\Debug\net5.0\runtimes\win-x64

01/15/2021  07:07 PM    <DIR>          .
01/15/2021  07:07 PM    <DIR>          ..
01/15/2021  07:07 PM    <DIR>          native
               0 File(s)              0 bytes

 Directory of ..\bin\Debug\net5.0\runtimes\win-x64\native

01/15/2021  07:07 PM    <DIR>          .
01/15/2021  07:07 PM    <DIR>          ..
12/10/2020  01:37 PM         8,343,552 realm-wrappers.dll
               1 File(s)      8,343,552 bytes

 Directory of ..\bin\Debug\net5.0\runtimes\win-x86

01/15/2021  07:07 PM    <DIR>          .
01/15/2021  07:07 PM    <DIR>          ..
01/15/2021  07:07 PM    <DIR>          native
               0 File(s)              0 bytes

 Directory of ..\bin\Debug\net5.0\runtimes\win-x86\native

01/15/2021  07:07 PM    <DIR>          .
01/15/2021  07:07 PM    <DIR>          ..
12/10/2020  01:36 PM         7,024,128 realm-wrappers.dll
               1 File(s)      7,024,128 bytes

     Total Files Listed:
              14 File(s)     45,175,430 bytes
              32 Dir(s)  38,008,614,912 bytes free

So to clarify - you are running a .NET 5.0 Console app on Windows 10 and you installed the Realm package via the package manager integrated inside VS? And you’re running the project from the VS UI (either with or without a debugger)? That should definitely be a supported scenario and NuGet should add references to the correct native dlls. The two things I can suggest trying out are:

  1. Delete the bin, obj folders and try to clean/rebuild your solution.
  2. Try using the dotnet command line tool to restore and run your project.

If none of that works, it would help a lot if you could archive your project and send it to us. While most of the issues we’ve seen with missing native dependencies have been due to NuGet caching/not restoring the correct thing, it’s certainly possible that there’s a corner case we haven’t covered that you’re hitting.

Note: Unrelated to the issue you’re seeing, there’s a regression in 10.0.0-beta.3 which prevents establishing sync connection on Windows due to certificate validation failure. We’ve just released 10.0.0-beta.5 which resolves that, so when you get past the missing wrappers dll, might be worth upgrading to that one.

Nikola,
Thank you for your answer. That was the exact use case, as you described.
I’ve managed to get this to work on different machine. Unfortunately after playing around with writes/updates my app crashes currently on
var realm = Realm.GetInstance(config);
without an exception, just leaving this error code behind:

(process 11616) exited with code -1073741819.

Is this with beta.3 or beta.5? And is it something reproducible/deterministic or does it crash randomly?