realm-dotnet: Realm.NET SDK 5.01 throws exception when filter returns null

On Realm.NET SDK 5.01 Windows 10.0.19041 Visual Studio 2019 16.7.3 Realm Cloud v3.28.2

Running VS in Debug mode Realm.NET SDK Version 4.3.0 this snippet returns null when none found and allows a null check

string filter = $"OrderDetail.OrderDetailId == '{rOrderDetailWithoutJob.OrderDetailId}'";
Data.Job rJob = realm.All<Data.Job>().Filter(filter).FirstOrDefault();
if (rJob != null)
...

On Realm.NET SDK Version 5.1.0 the line Data.Job rJob = realm.All<Data.Job>().Filter(filter).FirstOrDefault(); throws an exception when rJob is null. The exception message is

Key not found

OrderDetail.OrderDetailId is the primary key and it is not null rJob is null so of course the primary key is null

Have I missed a breaking change?

Here is the stack trace

   at Realms.NativeException.ThrowIfNecessary(Func`2 overrider)
   at Realms.CollectionHandleBase.TryGetObjectAtIndex(Int32 index, ObjectHandle& objectHandle)
   at Realms.RealmResultsVisitor.VisitMethodCall(MethodCallExpression node)
   at Realms.RealmResultsProvider.Execute(Expression expression)
   at Realms.RealmResultsProvider.Execute[T](Expression expression)
   at Wibble.Services.DataService.<>c__DisplayClass33_0.<RestoreLinksFromOrderDetailsToJobs>b__0() in C:\Repos\FSL\Wibble\Services\DataService.cs:line 397
   at Realms.Realm.Write(Action action)
   at Wibble.Services.DataService.RestoreLinksFromOrderDetailsToJobs() in C:\Repos\FSL\Wibble\Services\DataService.cs:line 391
   at Wibble.Services.DataService.CheckOrphans() in C:\Repos\FSL\Wibble\Services\DataService.cs:line 361
   at Wibble.Services.DataService.<CheckDbAsync>d__25.MoveNext() in C:\Repos\FSL\Wibble\Services\DataService.cs:line 264
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at UUWP.Device.StartDevice.<StartAsync>d__0.MoveNext() in C:\Repos\FSL\UUWP\Device\StartDevice.cs:line 17
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at UUWP.App.<OnLaunched>d__5.MoveNext() in C:\Repos\FSL\UUWP\App.xaml.cs:line 41

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 19 (5 by maintainers)

Most upvoted comments

Root cause found. We will release a fix as soon as possible.

The exception is no longer thrown on the test database where we first struck the error. Thank you @nirinchev @jedelbo