realm-dotnet: Xamarin android Crash
Cross-posted from realm/realm-cocoa#3574:
Hi Team !
I install Realm to project via nuget to test this. When it run to
var freshRealm = Realm.GetInstance(); --> crash here Below is the exception:
{System.NullReferenceException: Object reference not set to an instance of an object
at Realms.Realm.CreateRealmObjectMetadata (System.Type realmObjectType) [0x00019] in :0
at System.Linq.Enumerable.ToDictionaryType,Type,Metadata [0x0002f] in /Users/builder/data/lanes/2185/53fce373/source/mono/mcs/class/System.Core/System.Linq/Enumerable.cs:2924
at System.Linq.Enumerable.ToDictionaryType,Type,Metadata [0x00000] in /Users/builder/data/lanes/2185/53fce373/source/mono/mcs/class/System.Core/System.Linq/Enumerable.cs:2911
at Realms.Realm..ctor (Realms.SharedRealmHandle sharedRealmHandle, Realms.RealmConfiguration config) [0x00037] in :0
at Realms.Realm.GetInstance (Realms.RealmConfiguration config) [0x00171] in :0
at SaveCall.Repositories.RealmRepository.GetData () [0x0000e] in D:\Projects\SaveCall\SaveCall\Repositories\RealmRepository.cs:30 }
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 35 (17 by maintainers)
Commits related to this issue
- #541 Android crash in GetInstance Realm.cs - Realm static ctor - change error reporting of missing WovenAttribute to throw rather than just Debug.Writeline — committed to realm/realm-dotnet by AndyDentFree 8 years ago
- #541 Android crash in GetInstance Realm.cs - Realm static ctor - remove Debug.Writeline check loop as it does nothing. Throwing an exception here ended up buried as inner exception so no good for u... — committed to realm/realm-dotnet by deleted user 8 years ago
- Merge #541 Android crash in GetInstance Including manual merge with edits of CHANGELOG.md — committed to realm/realm-dotnet by AndyDentFree 8 years ago
confirmed. Seems like switching “Linking” to “None” plays the trick. Really annoying bug 😐
Progress!
This is definitely an error in the Fody weaving. I have added better error handling in
Realm.CreateRealmObjectMetadata
which is being invoked (via LINQ) when you callGetInstance
. It’s part of the internal schema construction which occurs at runtime.So now you will get a better diagnostic exception than the
NullReferenceException
. You get anArgumentException
with a message like The class RDB2.Dog has not been woven with Fody.I am still trying to work out why Fody is not weaving this code and provide better diagnostics for that failure.
Just to note on “NottieBear” comment. I’ve just tested his solution - it does not fixing the issue for me. Practically I cant go release build since without linking my result app is nearly 60 MB for just a simple slide. It’s a no-go situation 😐
@jerryno6 can you please confirm your problem is due to a lack of the
Import...Fody.targets
in your.csproj
as detailed aboveOK, got it unpacked and looking at it now (over dinner in Western Australia).