Comments (7)
This has been solved with #3451, so I am closing it
from realm-dotnet.
➤ PM Bot commented:
Jira ticket: RNET-1128
from realm-dotnet.
Hi @softlion, thanks for your report.
The exception that you're seeing should be raised when trying to get a SyncSession
on a local realm. From the code snippets that you posted it seems you're indeed creating a local realm, but I don't see you accessing SyncSession
anywhere, so I'm not sure how it could happen. I also took a look at our source code and we access SyncSession
only with a synchronized realm (when opening the realm with FlexibleSyncConfiguration
or PartitionSyncConfiguration
), so it shouldn't be possible.
Is that the whole stack trace you're getting? From that I can't see where the SyncSession
is accessed.
Would it be possible to for you to create a repro case and send it to us? This would be really helpful
from realm-dotnet.
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.
But that used to work, as I am only republishing an existing app with the latest nugets.
from realm-dotnet.
Ok, this makes sense. It seems that System.Text.Json
is ignoring the IgnoreDataMember
attribute we put on the source generated class properties so that they're ignored by the serialization. During the serialization System.Text.Json
is trying to access DbWallet.Realm.SyncSession
and so the exception is raised.
It seems we need to add the JsonIgnore
attribute to be compatible with System.Text.Json
. In the meanwhile, you can add special support for IgnoreDataMember
as explained here:
//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?
from realm-dotnet.
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 Realm
property on DBWallet
, even though it's annotated with IgnoreDataMember
. I don't think we can polyfill JsonIgnoreAttribute
, so we'll probably need to apply it if possible based on the compilation target.
from realm-dotnet.
Ok, this makes sense. It seems that
System.Text.Json
is ignoring theIgnoreDataMember
attribute we put on the source generated class properties so that they're ignored by the serialization. During the serializationSystem.Text.Json
is trying to accessDbWallet.Realm.SyncSession
and so the exception is raised.It seems we need to add the
JsonIgnore
attribute to be compatible withSystem.Text.Json
. In the meanwhile, you can add special support forIgnoreDataMember
as explained here://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?
maui, realm, json, and some others.
It may not have worked previously though, it may only not have reported the crash.
The tools have improved and now report the crash.
Anyway now we found the issue.
from realm-dotnet.
Related Issues (20)
- Compacting a Realm results in an upgrade prompt in Realm Studio HOT 2
- Encrypted Realm created on Android won't open on Windows HOT 5
- Trying to open a particular Realm DB file throws the following exception - "Upgrading from file format version 22 to 24 D:\a\realm-dotnet\realm-dotnet\wrappers\realm-core\src\realm/util/encrypted_file_mapping.hpp:180: [realm-core-14.5.1] Assertion failed: local_ndx < m_page_state.size() with (local_ndx, m_page_state.size(), size_t(addr), size_t(m_addr), m_page_shift) = [85, 1, 2331762327552, 2331762294784, 16] <backtrace not supported on this platform>" HOT 11
- SDKs should not consume stitch_ prefixed fields HOT 1
- Error when trying to migrate IList data type with DynamicApi.GetList HOT 6
- IRealmCollection SubscribeForNotifications not working!!! HOT 7
- Add support for Migration.FindInNewRealm HOT 1
- RealmResults (from Realm live queries) no longer notify UI observers HOT 5
- ToDictionary(Tkey, Filter) not filter HOT 3
- Other meessage when try add Apikey to anonymous user HOT 2
- Realm gets deleted on Compact HOT 2
- Wrong notification behaviour when subscribing both with `CollectionChanged` and `SubscribeForNotifications` HOT 2
- ShouldCompactOnLaunch not available for synchronized Realms HOT 1
- Collection.Filter should error out if argument is a removed object HOT 1
- Assigning a collection to a RealmValue property seems to merge it with other objects rather than replace it HOT 1
- TypeInitializationException on initialization HOT 3
- Incorrect argument parsing in test client HOT 1
- Flexible schema POC HOT 1
- No properties in xxxRealmObject HOT 6
- Support using a log level for a specific log category HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from realm-dotnet.