Realm-dotnet: [Xamarin forms] Realm while adding PropertyChanged.Fody only Primary keys stored rest of Null version 4.0

Created on 21 Jun 2019  路  12Comments  路  Source: realm/realm-dotnet

I had earlier realm 3.x version and I have upgraded now into version 4.0 now add PropertyChanged.Fody only primary keys will stored rest of stored as empty value?
please check below screenshot

image



Goals

It has to work as it is like work 3.x

Expected Results

It has to work as it is like work 3.x

Actual Results

Only Primary keys stored rest of empty or null

Steps to Reproduce

  1. Existing version of 3.x now upgrade to 4.0
  2. add PropertyChanged.Fody Nuget and run application
  3. check the data stored in realm file

Code Sample

Here is sample https://github.com/jitendrajadav/XamarinRealm

Version of Realm and Tooling

  • Realm Object Server Version: 4.0
  • Microsoft Visual Studio Professional 2019
    Version 16.1.3
    VisualStudio.16.Release/16.1.3+29009.5
    Microsoft .NET Framework
    Version 4.8.03752

Installed Version: Professional

VisualStudio.Mac 1.0
Mac Extension for Visual Studio

Workflow Manager Tools 1.0 1.0
This package contains the necessary Visual Studio integration components for Workflow Manager.

Xamarin 16.1.0.543 (d16-1@34a619991)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer 16.1.0.418 (remotes/origin/d16-1@5b958bb10)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates 16.2.112 (4db4af4)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK 9.3.0.22 (HEAD/8e7764fdf)
Xamarin.Android Reference Assemblies and MSBuild support.
Mono: mono/mono/2018-08@3cb36842fc4
Java.Interop: xamarin/java.interop/d16-1@5ddc3e3
LibZipSharp: grendello/LibZipSharp/d16-1@44de300
LibZip: nih-at/libzip/rel-1-5-1@b95cf3f
ProGuard: xamarin/proguard/master@905836d
SQLite: xamarin/sqlite/3.27.1@8212a2d
Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-1@acabd26

Xamarin.iOS and Xamarin.Mac SDK 12.10.0.153 (750a879)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

O-Community P-3-Optional T-Bug

All 12 comments

Any update on it?

We don't officially support Fody.PropertyChanged but also try not to break terribly when it is included. Can you try disabling it for your Realm models and see if that fixes the issue?

I can confirm the issue is caused by PropertyChanged.Fody, and it exists across platforms (not Xamarin.Forms-specific).

Persistent properties on models are successfully assigned values after creation, and can be read without issue before calling Realm.Add(RealmObject, bool); Once the add operation returns, the model loses all its properties besides the one marked as Primary Key. Nothing was saved in the local Realm either.

Thank you @nirinchev this is problem is only due to PropertyChanged.Fody if I removed PropertyChanged.Fody then this will work fine that is how @VaslD also confirm. so while adding PropertyChanged.Fody how would I go ahead?

@jitendrajadav PropertyChanged.Fody has two modes: opt-in and opt-out.

The default is opt-out. Everything that implements INotifyPropertyChanged will be modified unless already reporting property changes themselves, or opted-out. Add [DoNotNotify] on a type or property to opt-out.

I'm trying this method but it's a tedious progress since I have A LOT realm models.


The other solution is opt-in. Nothing is done unless a type implementing INotifyPropertyChanged matches an opt-in filter of PropertyChanged.Fody. This is turned on by adding [assembly: PropertyChanged.FilterType("...")] typically in AssemblyInfo.cs. The filter parameter is RegEx rules used to match type names.

This didn't work for me for some reason, maybe my RegEx is rusty. Try this out first. It sounds slightly better because you can use RegEx, so no more attributing EVERY class to fix ONE bug.

Thank you @VaslD it work for me now opt out like [DoNotNotify] but any other permanent solution is there?

[DoNotNotify] is a permanent solution per se. Since all RealmObjects fully implement INotifyPropertyChanged, there is zero work to be done by _PropertyChanged.Fody_. Unless you encounter drawbacks, you can keep those attributes as long as you like.

However I do think either _PropertyChanged.Fody_ or _Realm.NET_ team should properly handle the situation when both NuGets are installed. Maybe blacklist each other somehow so code injection doesn鈥檛 happen twice. I鈥檒l reference this issue on __PropertyChanged.Fody__鈥檚 repo and see if they can do anything about it.

We do try to add DoNotNotify to Realm objects but it seems it broke with the latest update. I'll try to take a look later this week and see if it's an easy fix.

Sure @nirinchev thank you:)

When we came across this issue, simply switching the order of Realm and PropertyChanged weavers fixed it.

Hi everyone! I had exactly this same problem, but by doing what @pikausp says it solved everything. Simply place PropertyChanged before Realms in the FodyWeavers file.

I had this same issue and I solved by switching the two weavers as follow:

<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
  <PropertyChanged />
  <Realm/>
</Weavers>

like this it works. Maybe something to write in the docs, as it made me lose quite a bit of time debugging it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

StephenBeirlaen picture StephenBeirlaen  路  8Comments

MtMovo picture MtMovo  路  3Comments

sunthx picture sunthx  路  8Comments

RealmBot picture RealmBot  路  4Comments

sunniejai picture sunniejai  路  15Comments