Uploaded image for project: 'Realm .NET SDK'
  1. Realm .NET SDK
  2. RNET-251

Realm.NET SDK 5.01 throws exception when filter returns null

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Critical - P2 Critical - P2
    • None
    • Affects Version/s: None
    • Component/s: None

      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
      

            Assignee:
            jorgen.edelbo@mongodb.com Jørgen Edelbo
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: