mbdavid / LiteDB

LiteDB - A .NET NoSQL Document Store in a single data file
http://www.litedb.org
MIT License
8.62k stars 1.25k forks source link

[QUESTION] Migration Problem - finding invalid cast #1662

Open bluekuen opened 4 years ago

bluekuen commented 4 years ago

Hello,

i have a problem with migrating to a newer version. I added a few fields to my data model and now get an InvalidCastException:

04-30 16:01:38.240 F/egg.mybusinessapp( 1851): runtime.cc:638] JNI DETECTED ERROR IN APPLICATION: JNI NewString called with pending exception android.runtime.JavaProxyThrowable: System.InvalidCastException: Specified cast is not valid. 04-30 16:01:38.240 F/egg.mybusinessapp( 1851): runtime.cc:638] at (wrapper dynamic-method) System.Object.lambda_method(System.Runtime.CompilerServices.Closure,object,object) 04-30 16:01:38.240 F/egg.mybusinessapp( 1851): runtime.cc:638] at LiteDB.BsonMapper.DeserializeObject (System.Type type, System.Object obj, LiteDB.BsonDocument value) [0x0008b] in <9e5fde0ddc6f45bfbe6bed2535394f2f>:0 04-30 16:01:38.240 F/egg.mybusinessapp( 1851): runtime.cc:638] at LiteDB.BsonMapper.Deserialize (System.Type type, LiteDB.BsonValue value) [0x00202] in <9e5fde0ddc6f45bfbe6bed2535394f2f>:0 04-30 16:01:38.241 F/egg.mybusinessapp( 1851): runtime.cc:638] at LiteDB.BsonMapper.DeserializeList (System.Type type, LiteDB.BsonArray value) [0x0002e] in <9e5fde0ddc6f45bfbe6bed2535394f2f>:0 04-30 16:01:38.241 F/egg.mybusinessapp( 1851): runtime.cc:638] at LiteDB.BsonMapper.Deserialize (System.Type type, LiteDB.BsonValue value) [0x0013e] in <9e5fde0ddc6f45bfbe6bed2535394f2f>:0 04-30 16:01:38.241 F/egg.zasetmobil( 1851): runtime.cc:638] at LiteDB.BsonMapper.DeserializeObject (System.Type type, System.Object obj, LiteDB.BsonDocument value) [0x00085] in <9e5fde0ddc6f45bfbe6bed2535394f2f>:0 04-30 16:01:38.241 F/egg.mybusinessapp( 1851): runtime.cc:638] at LiteDB.BsonMapper.Deserialize (System.Type type, LiteDB.BsonValue value) [0x00202] in <9e5fde0ddc6f45bfbe6bed2535394f2f>:0 04-30 16:01:38.241 F/egg.mybusinessapp( 1851): runtime.cc:638] at LiteDB.BsonMapper.DeserializeList (System.Type type, LiteDB.BsonArray value) [0x0002e] in <9e5fde0ddc6f45bfbe6bed2535394f2f>:0 04-30 16:01:38.241 F/egg.mybusinessapp( 1851): runtime.cc:638] at LiteDB.BsonMapper.Deserialize (System.Type type, LiteDB.BsonValue value) [0x0013e] in <9e5fde0ddc6f45bfbe6bed2535394f2f>:0 04-30 16:01:38.241 F/egg.mybusinessapp( 1851): runtime.cc:638] at LiteDB.BsonMapper.DeserializeObject (System.Type type, System.Object obj, LiteDB.BsonDocument value) [0x00085] in <9e5fde0ddc6f45bfbe6bed2535394f2f>:0 04-30 16:01:38.241 F/egg.mybusinessapp( 1851): runtime.cc:638] at LiteDB.BsonMapper.Deserialize (System.Type type, LiteDB.BsonValue value) [0x00202] in <9e5fde0ddc6f45bfbe6bed2535394f2f>:0 04-30 16:01:38.241 F/egg.mybusinessapp( 1851): runtime.cc:638] at LiteDB.BsonMapper.DeserializeObject (System.Type type, System.Object obj, LiteDB.BsonDocument value) [0x00085] in <9e5fde0ddc6f45bfbe6bed2535394f2f>:0 04-30 16:01:38.241 F/egg.mybusinessapp( 1851): runtime.cc:638] at LiteDB.BsonMapper.Deserialize (System.Type type, LiteDB.BsonValue value) [0x00202] in <9e5fde0ddc6f45bfbe6bed2535394f2f>:0 04-30 16:01:38.241 F/egg.mybusinessapp( 1851): runtime.cc:638] at LiteDB.BsonMapper.ToObject (System.Type type, LiteDB.BsonDocument doc) [0x00028] in <9e5fde0ddc6f45bfbe6bed2535394f2f>:0 04-30 16:01:38.241 F/egg.mybusinessapp( 1851): runtime.cc:638] at LiteDB.BsonMapper.ToObject[T] (LiteDB.BsonDocument doc) [0x00000] in <9e5fde0ddc6f45bfbe6bed2535394f2f>:0 04-30 16:01:38.241 F/egg.mybusinessapp( 1851): runtime.cc:638] at LiteDB.LiteCollection1+d17[T].MoveNext () [0x00090] in <9e5fde0ddc6f45bfbe6bed2535394f2f>:0 04-30 16:01:38.241 F/egg.mybusinessapp( 1851): runtime.cc:638] at mybusinessapp.App.InitMyDevicesListAsync () [0x001d3] in C:\Users\cunnin\mybusinessapp\28-04-20\mybusinessapp\mybusinessapp\App.xaml.cs:273 04-30 16:01:38.241 F/egg.mybusinessapp( 1851): runtime.cc:638] at mybusinessapp.App.b20_0 () [0x00042] in C:\Users\cunnin\mybusinessapp\28-04-20\mybusinessapp\mybusinessapp\App.xaml.cs:236 04-30 16:01:38.241 F/egg.mybusinessapp( 1851): runtime.cc:638] at mybusinessapp.App.OnStart () [0x000de] in C:\Users\cunnin\mybusinessapp\28-04-20\mybusinessapp\mybusinessapp\App.xaml.cs:234 04-30 16:01:38.241 F/egg.mybusinessapp( 1851): runtime.cc:638] at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.b7_0 (System.Object state) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2019-10/android/release/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1021 04-30 16:01:38.241 F/egg.mybusinessapp( 1851): runtime.cc:638] at Android.App.SyncContext+<>c__DisplayClass2_0.b0 () [0x00000] in :0 04-30 16:01:38.241 F/egg.mybusinessapp( 1851): runtime.cc:638] at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in :0 04-30 16:01:38.241 F/egg.mybusinessapp( 1851): runtime.cc:638] at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in :0 04-30 16:01:38.241 F/egg.mybusinessapp( 1851): runtime.cc:638] at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.33(intptr,intptr) 04-30 16:01:38.241 F/egg.mybusinessapp( 1851): runtime.cc:638] at void mono.java.lang.RunnableImplementor.n_run() (RunnableImplementor.java:-2) 04-30 16:01:38.241 F/egg.mybusinessapp( 1851): runtime.cc:638] at void mono.java.lang.RunnableImplementor.run() (RunnableImplementor.java:30) 04-30 16:01:38.241 F/egg.mybusinessapp( 1851): runtime.cc:638] at void android.os.Handler.handleCallback(android.os.Message) (Handler.java:883) 04-30 16:01:38.241 F/egg.mybusinessapp( 1851): runtime.cc:638] at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:100) 04-30 16:01:38.241 F/egg.mybusinessapp( 1851): runtime.cc:638] at void android.os.Looper.loop() (Looper.java:214) 04-30 16:01:38.241 F/egg.mybusinessapp( 1851): runtime.cc:638] at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:7397) 04-30 16:01:38.241 F/egg.mybusinessapp( 1851): runtime.cc:638] at java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[]) (Method.java:-2) 04-30 16:01:38.241 F/egg.mybusinessapp( 1851): runtime.cc:638] at void com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run() (RuntimeInit.java:492) 04-30 16:01:38.241 F/egg.mybusinessapp( 1851): runtime.cc:638] at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:935) 04-30 16:01:38.241 F/egg.mybusinessapp( 1851): runtime.cc:638] 04-30 16:01:38.241 F/egg.mybusinessapp( 1851): runtime.cc:638] in call to NewString 04-30 16:01:38.241 F/egg.mybusinessapp( 1851): runtime.cc:638] from void mono.java.lang.RunnableImplementor.n_run() 04-30 16:01:38.241 F/egg.mybusinessapp( 1851): runtime.cc:638] 04-30 16:01:38.241 F/libc ( 1851): Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 1851 (egg.zasetmobile), pid 1851 (egg.mybusinessapp) `

How can i find out wich property it is that failed to cast? Any help is highly appreciated!

Kind regards, bluekuen

lbnascimento commented 4 years ago

@bluekuen Could you provide your data class?

lbnascimento commented 4 years ago

@bluekuen Just looking at it, I don't see anything particularly wrong. You mentioned you recently added some fields to the model, what are those fields?

I want to run an example that uses your class, but for that I'll need the base class and all other classes used (you can remove methods if you want, leaving only attributes and properties).

bluekuen commented 4 years ago

I'm sorry i just got problems with my chef as i'm not allowed to publish that code. If there would be a method to get the exact property which fails to cast, that would be great. I just checked which properties are new and it were these here:

public byte[] StatisticFileData { get; set; } public string[] MetaDataStatisticFile { get; set; } public byte[] StatisticDeviceData { get; set; } public string[] MetaDataStatisticDevice { get; set; }

    public byte[] ErrorFileData { get; set; }
    public string[] MetaDataErrorFile { get; set; }
    public byte[] ExtErrorDeviceData { get; set; }
    public string[] MetaDataExtErrorDevice { get; set; }

What'S thescenario when fileds have been added to the database? What happens at deserialisation? Is it crashing then?

Much thanks for your help by the way! really appreciate it!

bluekuen commented 4 years ago

Is it possible to remove a custom type registration? I just need for the migration and then want to go back to the standard.

lbnascimento commented 4 years ago

@bluekuen I would suggest including the LiteDB source code in your project and adding a break point to the DeserializeObject method in BsonMapper.Serialize.cs.

Regarding custom serialization, it is not currently possible to remove it once added. What are you trying to accomplish?

bluekuen commented 4 years ago

I try to find the property which can't be deserialized with a custom deserializer.

bluekuen commented 4 years ago

I will try including the source code, thanks for the help. I will try on Monday again! Thanks again for the help!