Issue with adding realm to the project

I am trying to add nuget package for Realm to a project created in .net framework 4.7.2 and I have problem with the reference to realm-wrappers. It was added when I installed Realm package but I think something is wrong with it because its paths contains osx (I am working on Windows machine). The reference below has the same problem.

I tried to add references to windows dll manually but I am getting this error:

Please advise.

The .dylib being referenced is a visualization bug in Visual Studio - it won’t be bundled/used in your compiled executable. You don’t need to add the references manually as they should be automatically resolved and added by NuGet. Barring the visualization issue showing a warning about the macOS .dylib, are you seeing compilation issues with your project?

There are no compilation errors, but exception is thrown at runtime.

Can you try adding a reference to Realm in your WebApplication project if you haven’t already?

I tried that and I have the same error.

Hm… sounds like either a Nuget/MSBuild cache issue - can you try clearing the obj/bin folders and rebuilding. If the problem persists, can you share your project so I can try and run it locally?

That didn’t help either. Here is link to github repository with this project.

As far as I can tell, the issue is that when using IIS Express, it will copy the assembly files to a temporary location. When it does that, however, it doesn’t preserve the folder structure, so the trick we use to automatically add the realm-wrappers.dll to path doesn’t work. What you could do is to either use IIS and create an actual site that is hosted off of your project dir (i.e. not IIS express) or add the folder where realm-wrappers.dll is to the process PATH. The code would look something like:

var binPath = @"*path-to-your-solution*\WebApplication11\bin";
var wrappersPath = Path.Combine(binPath, "lib", "win32", IntPtr.Size == 4 ? "x86" : "x64");
var path = wrappersPath + Path.PathSeparator + Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Process);
Environment.SetEnvironmentVariable("PATH", path, EnvironmentVariableTarget.Process);

On a side note, the Realm package added to your WebApplication project is not the same version as the one added to your ClassLibrary - you should remove Realm.Database and Realm.DataBinding and add only Realm.

1 Like

Thank you for your help.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.