Troubleshooting - .NET SDK

You may see a System.InvalidOperationException with the message “No properties in class, has linker stripped it?”.

There are three known causes of this exception:

  • You have no woven RealmObjects, probably because something went wrong with Fody. If this is the case, RealmSchema throws an exception. See Fody Weave Exceptions for details on how to fix this.
  • A linker has stripped properties from one or more RealmObjects, and Realm thinks those properties don't exist. This can occur if you have your Linker Behavior set to Link all assemblies but have not used the [Preserve(AllMembers = true)] attribute on the class declaration. The linker only preserves class members that you have referenced explicitly in the code or marked with the [Preserve(AllMembers = true)] attribute. This means that if you want to persist a property in realm and it is not referenced anywhere in your code, the linker may remove it, causing a schema mismatch.
  • You are using a code obfuscation tool which is interfering with model name detection. Realm relies on class names to generate the schema, so if a code obfuscation tool has hidden those class names, schema generation fails. To solve this, set your code obfuscation tool to ignore your model classes.

This common build failure is triggered when you have already built a project and then add a new RealmObject sub-class. Choosing to Build or Run your project does not rebuild the project thoroughly enough to invoke the Fody Weaver. To fix this, choose to Rebuild your project.

You may see a warning in the build log about classes not having been woven. This indicates that the Fody weaving package is not properly installed. Here are some things to check:

  • First, check that the FodyWeavers.xml file contains an entry for Realm.
  • It is also possible that the installation of Fody has failed. Users have experienced this with Visual Studio 2015 and versions of NuGet Package Manager prior to version 3.2. To diagnose this, use a text editor to check that your .csproj has a line importing Fody.targets, such as:

    <Import Project="..\packages\Fody.1.29.3\build\portable-net+sl+win+wpa+wp\Fody.targets"
    Condition="Exists('..\packages\Fody.1.29.3\build\portable-net+sl+win+wpa+wp\Fody.targets')" />

The easiest fix is to upgrade to a later version of NuGet Package Manager. If this doesn’t work, there may be a problem with Fody and Microsoft.Bcl.Build.targets. Removing the following line from your .csproj file might help:

<Import Project="..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets"
Condition="Exists('..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" />

Inside the WriteAsync() method, we check for a non-null SynchronizationContext.Current object to determine if the code executes on the UI thread. This check may be inaccurate if you have set Current in your worker threads. If you have set SynchronizationContext.Current in a worker thread, call the Write() method instead of WriteAsync().

For more information, see Asynchronous Writes.

Give Feedback

On this page