-
Notifications
You must be signed in to change notification settings - Fork 165
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]: Possible issue with Fody IL #3100
Comments
Can you share your models - particularly the |
I'll try, this is part of my prod app so lots of stuff going on: Models:
Some GameCenterViewModel code:
I came across the |
Initial test seems like |
Why do you think this is a Fody issue though? As far as I can tell from the stacktrace, it's something related to TeamId, which is a computed property that is not processed by the Realm.Fody weaver. It's possible I'm not seeing something, but it looks like it's caused by the LINQ expression that compares the team ids of Team1 and Team2 - it does look perfectly legal, but also not something that directly involves Realm. It's possible it's due to the way Team.StrongId is constructed from the Team.Id property, but that's not obvious at least from the stacktrace. |
Well nothing actually : D I just know it (likely*) ended up being Fody in my other case where I ran into this, and saw similar stack traces in that scenario as this one. This was the runtime error for that one:
The Microsoft team indicated this is a result of reflection stuff, and I guess I assumed Fody was my only exposure to that sort of code currently (https://discord.com/channels/732297728826277939/732297808148824115/1029472609303269386). It also was the same "everything has been working fine, then I shuffled some code around slightly and it now crashes at runtime" behavior. I also assume if not many have run into it, its the same other circumstances of not many people moved to Maui / net6.0 yet, and that having different AOT rules/defaults. But yeah the StrongId stuff has been in place for ~3 months now, but only just got this crash this week. The models have been mostly static as well. I have many other instances of StrongId models, and those all use similar access patterns. |
Yeah, the thing is Fody doesn't really do any reflection. At least what our weaver does right now is to replace the property implementation which looks like: class Foo : RealmObject
{
private string <backing_field_bar>;
public string Bar
{
get => <backing_field_bar>;
set => <backing_field_bar> = value;
}
} to make it look like: class Foo : RealmObject
{
private string <backing_field_bar>;
public string Bar
{
get
{
if (IsManaged)
{
return base.GetValue<string>("Bar");
}
return <backing_field_bar>;
}
set
{
if (IsManaged)
{
base.SetValue("Bar", value);
}
else
{
<backing_field_bar> = value;
}
}
}
} So not doing any reflection, just making sure for managed objects we read/write data via the base class (which goes through the database) rather than via the backing field. It's certainly possible that there's some weird interaction which breaks the compiler somehow, but I'd be more inclined to attribute that to a bug with the compiler than the code generated by Fody. That being said, we recently released support for source generators, which almost entirely eliminates the need to synthesize IL at compile time, so might be worth giving it a shot. |
Closing this as the workaround seems to be sufficient. Feel free to reopen if you want us to investigate deeper. |
What happened?
Getting a crash in release build
I got this once previously when using ReactiveUI's Fody weaver attributes, and was able to resolve by removing them. I started down the path of verifying if moving to SG would fix it here, but the current SG limitations make it hard to move over (e.g. #3085).
Repro steps
Similar to my issues with ReactiveUI, this came about pretty randomly after having done several release builds with Realm. The only thing I can think of that I added as an
EmbeddedObject
for the first time. Seemingly random, however.Version
10.18.0
What SDK flavour are you using?
Local Database only
What type of application is this?
Other
Client OS and version
iOS 15.6.1
Code snippets
No response
Stacktrace of the exception/crash you're getting
Relevant log output
No response
The text was updated successfully, but these errors were encountered: