Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Obscure exception when opening a Realm with readonly: true and models mismatching the schema #2619

Closed
carbonete opened this issue Sep 11, 2021 · 6 comments · Fixed by #2621
Assignees

Comments

@carbonete
Copy link

carbonete commented Sep 11, 2021

What happened?

I have a realm .Net Standard project shared by a Core 3.1 program and a Xamarin UWP program.

When called in Xamarin i receive this error.

null
Exception backtrace:

Repro steps

Call in Xamarin with encrypted Key and readonly . This work in .Net Core 3.1

Version

10.5.0

What SDK flavour are you using?

Local Database only

What type of application is this?

Xamarin

Client OS and version

Microsoft Windows 10 Pro Version	10.0.19043 Build 19043

Code snippets

    #region Properties

    private Realm realmInstance;

    private RealmConfigurationBase realmConfigurationBase;

    #endregion


    #region Constructor
    public DB(string db, string dir, byte[] cryptKey, bool onlyRead)
    {
    #if DEBUG
        log();
    #endif

        realmConfigurationBase = new RealmConfiguration(Path.Combine(dir,db))
        {
            EncryptionKey = cryptKey,
            IsReadOnly = onlyRead
        };
        try
        {
            realmInstance = Realm.GetInstance(realmConfigurationBase);
        }
        catch (Exception err)
        {
            var t = err;
            throw;
        }
        
    }
    private void log()
    {
        Logger.LogLevel = LogLevel.All;
        Logger.Default = Logger.Function(message =>
        {
            System.Diagnostics.Debug.WriteLine(message);
        });
    }

Stacktrace of the exception/crash you're getting

at Realms.NativeException.ThrowIfNecessary(Func`2 overrider)
   at Realms.SharedRealmHandle.GetTableKey(String tableName)
   at Realms.Realm.CreateRealmObjectMetadata(ObjectSchema schema)
   at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()
   at Realms.Realm.RealmMetadata.Add(IEnumerable`1 objectsMetadata)
   at Realms.Realm..ctor(SharedRealmHandle sharedRealmHandle, RealmConfigurationBase config, RealmSchema schema)
   at Realms.RealmConfigurationBase.GetRealm(SharedRealmHandle sharedRealmHandle, RealmSchema schema)
   at Realms.RealmConfiguration.CreateRealm(RealmSchema schema)
   at LexSemanticDicPersistence.Context.DB..ctor(String db, String dir, Byte[] cryptKey, Boolean onlyRead)

Relevant log output

LogLevel.All only register this

Exception thrown: 'Realms.Exceptions.RealmException' in Realm.dll
@nirinchev
Copy link
Member

Hey, this looks like an issue with the schema not matching the models. We should definitely handle this error better, but you can probably work around it by making sure your c# models match exactly the schema of the Realm you're opening. Typically, the SDK would just update the Realm schema, but since you're opening it as read-only, it is not allowed to write to the file. Then, when it tries to lookup the table for a particular class, it fails because that table doesn't exist.

@carbonete
Copy link
Author

Same problem with 10.4.1

@nirinchev
Copy link
Member

As I explained above, this issue is expected. The error message could be better, but you can't open a readonly Realm with models that don't match the schema.

@nirinchev nirinchev changed the title [Bug]: backtrace not supported on this platform [Bug]: Obscure exception when opening a Realm with readonly: true and models mismatching the schema Sep 12, 2021
@nirinchev
Copy link
Member

This is a Core bug - reported it here: realm/realm-core#4901.

@carbonete
Copy link
Author

Hi @nirinchev , sorry i write about 10.4.1 before see you answer. Thanks for attention at weekend.

But, both programs call same DLL that contains Schema. I forget mention that this app has working with other dll that use SYNC to users specific data.
After your answer at https://www.mongodb.com/community/forums/t/how-to-mix-sync-realm-and-total-offline-db/123658 ,
I change both projects to include ObjectClasses in configuration. And problem is solved, i can open with read only true, i think they try make SYNC with this local database, and need to made changes causing error.

Thanks for attention

@sync-by-unito
Copy link

sync-by-unito bot commented Oct 1, 2021

➤ Nikola Irinchev commented:

Reopening because it might after all be an SDK issue. I'll investigate.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants