Join us at MongoDB.local London on 7 May to unlock new possibilities for your data. Use WEB50 to save 50%.
Register now >
Docs Menu
Docs Home
/ /
Kit de desarrollo de software .NET

Troubleshooting - .NET SDK

Es posible que veas un System.InvalidOperationException con el mensaje "No hay propiedades en la clase, ¿el enlazador las ha eliminado?".

Hay tres causas conocidas para esta excepción:

Este error de compilación común se activa cuando ya ha compilado un proyecto y luego agrega una nueva subclase RealmObject. Al elegir Build o Run su proyecto no se reconstruye con la suficiente precisión como para invocar Fody Weaver. Para solucionar esto, elija Rebuild su proyecto.

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.

  • También es posible que la instalación de Fody haya fallado. Los usuarios han experimentado esto con Visual Studio 2015 y versiones de NuGet administrador de paquetes anteriores a la versión 3.2. Para diagnosticar esto, utiliza un editor de texto para comprobar que tu .csproj tenga una línea que importe Fody.targets, como:

    <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.

Puede que veas un System.NotSupportedException con el mensaje "AddDefaultTypes debe llamarse antes de crear una instancia Realm". Esto puede ocurrir cuando se tienen múltiples Proyectos que contienen modelos de Realm y se abre una instancia Realm antes de que todos hayan sido cargados en memoria.

.NET uses lazy loading to improve performance. An assembly is not loaded until one or more of the types it contains is needed. However, Realm relies on the module initializer to register all of the types in its default schema. When you first open a realm, the default schema gets locked, and any attempt to register more types will result in the exception above.

There are 3 ways to resolve this issue:

  1. Puedes colocar tus modelos de realm en el mismo conjunto donde llamas a Realm.GetInstance.

  2. Puedes precargar el ensamblado que contiene tus objetos Realm creando un método estático en el ensamblado, y luego llamando a ese método desde el código de tu aplicación:

    // In your models assembly
    public static class MyAssemblyLoader
    {
    public static void LoadMe() {}
    }
    // In your app
    public void Initialize()
    {
    MyAssemblyLoader.LoadMe();
    }
  3. You can explicitly specify the Realm schema when initializing the realm:

    var config = new RealmConfiguration
    {
    Schema = new[] { typeof(Person), typeof(Company), ... }
    }

In iOS or iPad devices with little available memory, or where you have a memory-intensive application that uses multiple realms or many notifications, you may encounter the following error:

libc++abi: terminating due to an uncaught exception of type std::bad_alloc: std::bad_alloc

Este error normalmente indica que un recurso no se puede asignar porque no hay suficiente memoria disponible.

If you are building for iOS 15+ or iPad 15+, you can add the Extended Virtual Addressing Entitlement to resolve this issue.

Add these keys to your Property List, and set the values to true:

<key>com.apple.developer.kernel.extended-virtual-addressing</key>
<true/>
<key>com.apple.developer.kernel.increased-memory-limit</key>
<true/>

Volver

Compatibilidad

En esta página