xUnit tests throw System.TypeInitializationException with Realm

I am working on Xamarin.Forms project. I have a xUnit test project targeting dotnet 5. The xunit NuGet version is 2.4.1. When I run the tests I get the error mentioned in the title and all tests fail. The complete test detail summary is as follows:

Message:
System.TypeInitializationException : The type initializer for '<Module>' threw an exception.
---- System.InvalidProgramException : The JIT compiler encountered invalid IL code or an internal limitation.

Stack Trace:
LoginTest.ctor()
----- Inner Stack Trace -----
cctor()

This only happens when there is Realm Database used in the app. If I Remove Realm Models along with all the realm related code the test runs and pass successfully. Here is the link to sample project.

The error has gone by removing the Realm Package from the Shared Project(code tested from this project). The realm package already installed in the Models project. which have all the Models of the App. The Shared project reference the Model project so it can still work with Realm.

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