To run PCL tests that uses Realm.
Tests must be performed without any Realm initialization exceptions.
<System.TypeInitializationException: The type initializer for 'Realms.SharedRealmHandle' threw an exception. ---> System.DllNotFoundException: realm-wrappers
Realm.GetInstance().
Console application:
public static int Main(string[] args)
{
return new AutoRun(typeof(TestsPCLClass).GetTypeInfo().Assembly).Execute(args);
}
Seems like the realm-wrappers binary is not copied to the final application. Is your console app .NET Core 2.0?
Thank you for the response. No, I used plain Console project.
Hm... so does this happen on Windows? If so, can you share the project that fails?
I also have same issue on my Xamarin Forms iOS project. And UWP project works fine with same code.
"StackTrace": " at Realms.RealmConfiguration.CreateRealm (Realms.Schema.RealmSchema schema) [0x000c1] in <4602cbc0fa8c48fb8b9d2d660aa6b21c>:0
at Realms.Realm.GetInstance (Realms.RealmConfigurationBase config, Realms.Schema.RealmSchema schema) [0x0003e] in <4602cbc0fa8c48fb8b9d2d660aa6b21c>:0
at Realms.Realm.GetInstance (Realms.RealmConfigurationBase config) [0x0000a] in <4602cbc0fa8c48fb8b9d2d660aa6b21c>:0
"Msg": "The type initializer for 'Realms.SharedRealmHandle' threw an exception.",
I created a test project to demonstrate the issue: https://github.com/Prin53/Xamarin.Realm.Tests
Unfortunately, I have no prepared Windows machine.
@nirinchev +1 for iOS project
Thanks, I've been a little busy lately, but hope to be able to look into it soon.
I also get this error when using the iPhone Simulator
I had very similar problem - the realm db worked fine in the app (xamarin.forms android and ios) but I could not run unit tests on mac with nunit.consolerunner. It worked fine on windows but on mac there was System.TypeInitializationException for every test that accessed the db.
After 3h of searching I've come up with hacky workaround:
sudo cp ~/.nuget/packages/realm/3.0.0/runtimes/osx.10.10-x64/native/librealm-wrappers.dylib /Library/Frameworks/Mono.framework/Libraries/
with library in place I am able to run unit tests from command line and Rider. Visual Studio for Mac still does not work but I don't care that much about it - I find Unit test explorer in Rider superior anyway.
I hope this helps anyone until this is fixed.
I get same error. Realm 2.3.0. Both iOS and Android.
Same problem. Realm 3.2.1. Xamarin Forms Android and iOS. The error occurs when GetInstance() is called.
Output:
10-05 13:24:41.544 D/Mono (32035): DllImport attempting to load: 'realm-wrappers'.
10-05 13:24:41.545 D/Mono (32035): DllImport error loading library '/storage/emulated/0/Android/data/com.companyname.Aule/files/.__override__/librealm-wrappers': 'dlopen failed: library "/data/app/com.companyname.Aule-0CbMmActvN9ftxal3de3zg==/lib/arm64//storage/emulated/0/Android/data/com.companyname.Aule/files/.__override__/librealm-wrappers" not found'.
10-05 13:24:41.546 D/Mono (32035): DllImport error loading library '/storage/emulated/0/Android/data/com.companyname.Aule/files/.__override__/librealm-wrappers.so': 'dlopen failed: library "/data/app/com.companyname.Aule-0CbMmActvN9ftxal3de3zg==/lib/arm64//storage/emulated/0/Android/data/com.companyname.Aule/files/.__override__/librealm-wrappers.so" not found'.
10-05 13:24:41.547 D/Mono (32035): DllImport error loading library '/system/lib/librealm-wrappers': 'dlopen failed: library "/data/app/com.companyname.Aule-0CbMmActvN9ftxal3de3zg==/lib/arm64//system/lib/librealm-wrappers" not found'.
10-05 13:24:41.547 D/Mono (32035): DllImport error loading library '/system/lib/librealm-wrappers.so': 'dlopen failed: library "/data/app/com.companyname.Aule-0CbMmActvN9ftxal3de3zg==/lib/arm64//system/lib/librealm-wrappers.so" not found'.
10-05 13:24:41.548 D/Mono (32035): DllImport error loading library 'librealm-wrappers': 'dlopen failed: library "/data/app/com.companyname.Aule-0CbMmActvN9ftxal3de3zg==/lib/arm64/librealm-wrappers" not found'.
10-05 13:24:41.550 D/Mono (32035): DllImport error loading library 'librealm-wrappers.so': 'dlopen failed: library "/data/app/com.companyname.Aule-0CbMmActvN9ftxal3de3zg==/lib/arm64/librealm-wrappers.so" not found'.
10-05 13:24:41.551 D/Mono (32035): DllImport error loading library 'realm-wrappers': 'dlopen failed: library "/data/app/com.companyname.Aule-0CbMmActvN9ftxal3de3zg==/lib/arm64/realm-wrappers" not found'.
10-05 13:24:41.552 D/Mono (32035): DllImport error loading library '/storage/emulated/0/Android/data/com.companyname.Aule/files/.__override__/librealm-wrappers': 'dlopen failed: library "/data/app/com.companyname.Aule-0CbMmActvN9ftxal3de3zg==/lib/arm64//storage/emulated/0/Android/data/com.companyname.Aule/files/.__override__/librealm-wrappers" not found'.
10-05 13:24:41.553 D/Mono (32035): DllImport error loading library '/storage/emulated/0/Android/data/com.companyname.Aule/files/.__override__/librealm-wrappers.so': 'dlopen failed: library "/data/app/com.companyname.Aule-0CbMmActvN9ftxal3de3zg==/lib/arm64//storage/emulated/0/Android/data/com.companyname.Aule/files/.__override__/librealm-wrappers.so" not found'.
10-05 13:24:41.553 D/Mono (32035): DllImport error loading library '/system/lib/librealm-wrappers': 'dlopen failed: library "/data/app/com.companyname.Aule-0CbMmActvN9ftxal3de3zg==/lib/arm64//system/lib/librealm-wrappers" not found'.
10-05 13:24:41.554 D/Mono (32035): DllImport error loading library '/system/lib/librealm-wrappers.so': 'dlopen failed: library "/data/app/com.companyname.Aule-0CbMmActvN9ftxal3de3zg==/lib/arm64//system/lib/librealm-wrappers.so" not found'.
10-05 13:24:41.555 D/Mono (32035): DllImport error loading library 'librealm-wrappers': 'dlopen failed: library "/data/app/com.companyname.Aule-0CbMmActvN9ftxal3de3zg==/lib/arm64/librealm-wrappers" not found'.
10-05 13:24:41.556 D/Mono (32035): DllImport error loading library 'librealm-wrappers.so': 'dlopen failed: library "/data/app/com.companyname.Aule-0CbMmActvN9ftxal3de3zg==/lib/arm64/librealm-wrappers.so" not found'.
10-05 13:24:41.557 D/Mono (32035): DllImport error loading library 'librealm-wrappers': 'dlopen failed: library "/data/app/com.companyname.Aule-0CbMmActvN9ftxal3de3zg==/lib/arm64/librealm-wrappers" not found'.
10-05 13:24:41.557 W/Mono (32035): DllImport unable to load library 'dlopen failed: library "/data/app/com.companyname.Aule-0CbMmActvN9ftxal3de3zg==/lib/arm64/librealm-wrappers" not found'.
System.TypeInitializationException: The type initializer for 'Realms.SharedRealmHandle' threw an exception.
Any hits or workarounds?
I managed to make it work just by reinstalling the Nuget packages, but this time I installed each one separatelly :D
System.TypeInitializationException : The type initializer for 'Realms.SharedRealmHandle' threw an exception.
----> System.DllNotFoundException : realm-wrappers
this still seems to be an issue
I solved the issue by installing Realm nuget package for each project in the solution, as well as adding FodyWeaver.xml file to each one manually. FodyWeaver.xml have to be the same over the projects as it can be overriten during compilation.
I just had the same issue with a brand new Xamarin.Forms project. Then I found that I did not install the Realm package to the iOS project. After I did, the error changed a bit from System.DllNotFoundException: realm-wrappers to System.DllNotFoundException:
@rpath/realm-wrappers.framework/realm-wrappers. Sigh.
Magically, upgrading the shared Xamarin.Forms project and the native projects to Xamarin.Forms 4.2.0 (was 4.1.0) and Xamarin.Essentials 1.3.0 (was 1.2.0) solved the issue.
Most helpful comment
I get same error. Realm 2.3.0. Both iOS and Android.