Are boolean Realm Properties sort of special?

Hi folks,

I have come accross a behavior of RealmObject which I absolutely don’t understand. I am persisting emails in Realm. These RealmObjects have a property called IsRead:

public partial class Email : RealmObject
 {
        [PrimaryKey]
        public ObjectId Id { get; set; }

        [Indexed]
        public bool IsRead { get; set; }
....
}

This piece of code behaviors in a very weird way:

private void MarkAsReadAsync(ObjectId id, Email email)
{
  dowey = 0;
  // Debug.Assert(email.IsRead == false);

  if (email.IsRead == false)
  {
     dowey = 1000;
  }

  Debug.Assert(dowey == 1000);
}

One would like to think that when isRead equals ‘false’ dowey will equal to 1000, but no:

→ according to line 72 isRead bool should be equal to email.IsRead
→ according to the watch window however, they are different

This is not a pure Intellisense issue, since the binding on that property actually also evaluates to false.

What do I miss with bools here?

Thanks,
Aron

The second screenshot where dowey == 1000 is evaluated as false, you have dowey = 100 (one less zero) in the if case. That seems fixed in the 3rd screenshot, but it’s not clear whether the debugger evaluates dowey == 1000 to false.

1 Like

Yes, I have timely seen that issue in my examples, but messed up the picture after the forum software was telling me to use only 1 media.

Unfortunately, I cannot find the edit button, so here the refreshed screenshot

That looks like either an intellisense/debugger issue or something very suspiciously wrong. Can you instead try adding Console.WriteLine statement for email.IsRead at the start of the function.

1 Like

Did some outputs and they are consistent:

Value from local: True
Value from object: True
Dowey: 0
[um.denomail.ap] Explicit concurrent copying GC freed 28373(1458KB) AllocSpace objects, 0(0B) LOS objects, 49% free, 4305KB/8610KB, paused 307us total 8.065ms
Value from local: True
Value from object: True
Dowey: 0
Value from local: False
Value from object: False
Dowey: 1000

→ The value on IntelliSense is always false

I can therefore confirm that the issue materializes in IntelliSense, but the cause seems to be in the ReallmObject:

  • if I replace the realm object with a POCO, IntelliSense works properly
  • the property is an auto-property, but RealmObject must do sth in order to intercept it (so that it can raise the exception on setters-outside-of-write). This something seems then to confuse IntelliSense.

It’s likely the debugger trying to be clever and using the field value rather than the property itself. There’s little we can do to fix that with the current approach where we use IL weaving to replace the getter/setter of RealmObject properties. This will probably be alleviated once we switch to source generators.

1 Like