-
Notifications
You must be signed in to change notification settings - Fork 166
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
Crash: Realm.SyncSession is only valid for synchronized Realms #3562
Comments
➤ PM Bot commented: Jira ticket: RNET-1128 |
Hi @softlion, thanks for your report. Is that the whole stack trace you're getting? From that I can't see where the |
That triggers the issue. The key that triggers it is the json serializer (using System.Text.Json;) [Fact]
public async Task TriggerRealmBug()
{
using var db = Realm.GetInstance(new InMemoryConfiguration("unittests"));
var walletId = "someId";
var wallet = new DbWallet { WalletId = walletId };
await db.WriteAsync(() => { db.Add(wallet); });
wallet = db.Find<DbWallet>(walletId);
await db.WriteAsync(() => { wallet.Alias = "some new value"; });
var dbWallets = db.All<DbWallet>().ToList();
Assert.Single(dbWallets);
//Crash here
var jsonWallets = JsonSerializer.Serialize(db.All<DbWallet>().ToList());
} public partial class DbWallet : IRealmObject
{
[PrimaryKey]
public string WalletId { get; set; }
public string? Alias { get; set; }
} I worked around using a new domain object and mapperly. |
Ok, this makes sense. It seems that It seems we need to add the //NOTE: This is copied from the link above
var options = new JsonSerializerOptions
{
TypeInfoResolver = new DefaultJsonTypeInfoResolver
{
Modifiers = { DetectIgnoreDataMemberAttribute }
}
};
JsonSerializer.Serialize(new MyPoco(), options); // {"Value":3}
static void DetectIgnoreDataMemberAttribute(JsonTypeInfo typeInfo)
{
if (typeInfo.Kind != JsonTypeInfoKind.Object)
return;
foreach (JsonPropertyInfo propertyInfo in typeInfo.Properties)
{
if (propertyInfo.AttributeProvider is ICustomAttributeProvider provider &&
provider.IsDefined(typeof(IgnoreDataMemberAttribute), inherit: true))
{
// Disable both serialization and deserialization
// by unsetting getter and setter delegates
propertyInfo.Get = null;
propertyInfo.Set = null;
}
}
} To be honest I am surprised this was working before. You said you updated your nuget packages and this stopped working. What nuget packages did you exactly update? |
Edit: Looks like @papafe beat me to this 😅 This is just repeating what Ferdinando is saying, but with less detail. Looks like the json serializer is trying to serialize the |
maui, realm, json, and some others. Anyway now we found the issue. |
This has been solved with #3451, so I am closing it |
What happened?
realm 11.7.0
Real crashed while reading a table.
Exception:
Repro steps
Version
8.0
What Atlas Services are you using?
Local Database only
What type of application is this?
Other
Client OS and version
Maui. Android emulator API 33 (pixel 5) on windows 11.
Code snippets
Stacktrace of the exception/crash you're getting
Relevant log output
No response
The text was updated successfully, but these errors were encountered: