Search code examples
.netrealm

.Net Realms Assertion failed: !realm.is_in_transaction() turn on backtrace


I'm using Realms on .Net and I get the error

The active test run was aborted. Reason: Test host process crashed : D:\a\realm-dotnet\realm-dotnet\wrappers\realm-core\src\realm\object-store\impl\realm_coordinator.cpp:1160: [realm-core-13.23.4] Assertion failed: !realm.is_in_transaction() 12:03:26:319 <backtrace not supported on this platform>

I get this error occasionally when running my test suite and I've tried to resolve this issue reviewing all my code with realms ensuring that everything that changes entries is within a realm.Write but this still occurs.

I mostly just want to get the backtrace to show. I'm using .Net 8 and realms version 11.6.1


Solution

  • I had a similiar issue where my unit test failed occasionally with xUnit. I fixed it by using this nuget package: https://www.nuget.org/packages/Nito.AsyncEx.Context I wrapped each test in an asynccontext like this:

     [Fact]
    public void FilterTest()
    {
        AsyncContext.Run(() =>
        {
            var realmservice = new RealmService();
            DateTimeOffset offset = DateTime.Today;
            var dateTime = DateTime.Today;
            var universalTime = dateTime.ToUniversalTime();
            DateTimeOffset dateTimeOffset = universalTime.Add(offset.Offset);
            var entry = new DiaryEntry() { Partition = "test", Date = DateTime.Today };
            var realm = realmservice.Get();
            realm.Write(() => realm.Add(entry));
            var result = realm.All<DiaryEntry>().FirstOrDefault(t => t.StoredDate == dateTimeOffset);
            result!.Date.Should().Be(dateTimeOffset);
            realmservice.DisposeRealm();
            return Task.CompletedTask;
        });
    }
    

    I think had has to do something how xUnit runs its test under the hood. Hopefully this helps.