C# System.NotSupportedException Xamarin

C# System.NotSupportedException Xamarin,c#,exception,xamarin,exception-handling,icollection,C#,Exception,Xamarin,Exception Handling,Icollection,我有一个应用程序,有一个3步注册过程 姓名、电子邮件、密码(注册虚拟机内) 用户详细信息(用户配置文件内部) 药物摄入(在UserMedicineINC_vm内) 当我被导航到3)时,我能够通过1)和2),我看到了页面的UI,但突然出现了“未处理的异常”弹出框 调试输出中出现的错误: System.NotSupportedException: Don't know about System.Collections.Generic.ICollection`1[LoginSystem.Models.

我有一个应用程序,有一个3步注册过程

  • 姓名、电子邮件、密码(注册虚拟机内)
  • 用户详细信息(用户配置文件内部)
  • 药物摄入(在UserMedicineINC_vm内)
  • 当我被导航到3)时,我能够通过1)和2),我看到了页面的UI,但突然出现了“未处理的异常”弹出框

    调试输出中出现的错误:

    System.NotSupportedException: Don't know about System.Collections.Generic.ICollection`1[LoginSystem.Models.Medicine]
    
    我想这是因为我的Medicine类(在models文件夹中)中有这行代码:

    *Medicine和Medicine_事件定义了一些字段,如:

    public string Medicine_Name { get; set; }
    public string Medicine_Desc { get; set; }
    
    Xamarin是否禁止使用Icollections

    如果你知道发生了什么事,请告诉我。 谢谢

    *应用程序输出:

    06-19 10:26:50.382 E/EGL_emulation( 5282): tid 5308: eglSurfaceAttrib(1165): error 0x3009 (EGL_BAD_MATCH)
    06-19 10:26:50.382 W/OpenGLRenderer( 5282): Failed to set EGL_SWAP_BEHAVIOR on surface 0x9a966180, error=EGL_BAD_MATCH
    06-19 10:26:50.433 E/EGL_emulation( 5282): tid 5308: eglSurfaceAttrib(1165): error 0x3009 (EGL_BAD_MATCH)
    06-19 10:26:50.433 W/OpenGLRenderer( 5282): Failed to set EGL_SWAP_BEHAVIOR on surface 0x9a966060, error=EGL_BAD_MATCH
    06-19 10:26:50.663 E/EGL_emulation( 5282): tid 5308: eglSurfaceAttrib(1165): error 0x3009 (EGL_BAD_MATCH)
    06-19 10:26:50.663 W/OpenGLRenderer( 5282): Failed to set EGL_SWAP_BEHAVIOR on surface 0x9a7a0aa0, error=EGL_BAD_MATCH
    06-19 10:26:51.898 D/Mono    ( 5282): Assembly Ref addref LoginSystem[0x9dfec2a0] -> SQLite-net[0xad9e9dc0]: 2
    06-19 10:26:51.916 D/Mono    ( 5282): Unloading image System.Threading.Tasks.dll [0x9a853f00].
    06-19 10:26:51.916 D/Mono    ( 5282): Image addref System.Threading.Tasks[0x9a864300] -> System.Threading.Tasks.dll[0x9cc96000]: 6
    06-19 10:26:51.916 D/Mono    ( 5282): Config attempting to parse: 'System.Threading.Tasks.dll.config'.
    06-19 10:26:51.916 D/Mono    ( 5282): Config attempting to parse: '/usr/local/etc/mono/assemblies/System.Threading.Tasks/System.Threading.Tasks.config'.
    06-19 10:26:51.916 D/Mono    ( 5282): Assembly Ref addref SQLite-net[0xad9e9dc0] -> System.Threading.Tasks[0x9dfed020]: 4
    06-19 10:26:51.962 D/Mono    ( 5282): Unloading image System.Collections.dll [0xab2f7400].
    06-19 10:26:51.962 D/Mono    ( 5282): Image addref System.Collections[0xaec94f60] -> System.Collections.dll[0x9d004f00]: 7
    06-19 10:26:51.962 D/Mono    ( 5282): Config attempting to parse: 'System.Collections.dll.config'.
    06-19 10:26:51.962 D/Mono    ( 5282): Config attempting to parse: '/usr/local/etc/mono/assemblies/System.Collections/System.Collections.config'.
    06-19 10:26:51.962 D/Mono    ( 5282): Assembly Ref addref SQLite-net[0xad9e9dc0] -> System.Collections[0x9dfec4e0]: 5
    06-19 10:26:51.965 D/Mono    ( 5282): Unloading image System.Runtime.Extensions.dll [0xab2f7400].
    06-19 10:26:51.965 D/Mono    ( 5282): Image addref System.Runtime.Extensions[0xaec94f60] -> System.Runtime.Extensions.dll[0x9d007c00]: 6
    06-19 10:26:51.965 D/Mono    ( 5282): Config attempting to parse: 'System.Runtime.Extensions.dll.config'.
    06-19 10:26:51.965 D/Mono    ( 5282): Config attempting to parse: '/usr/local/etc/mono/assemblies/System.Runtime.Extensions/System.Runtime.Extensions.config'.
    06-19 10:26:51.965 D/Mono    ( 5282): Assembly Ref addref SQLite-net[0xad9e9dc0] -> System.Runtime.Extensions[0x9dfecb40]: 4
    06-19 10:26:51.965 D/Mono    ( 5282): Assembly Ref addref SQLite-net[0xad9e9dc0] -> SQLitePCLRaw.core[0xad9e9f40]: 2
    06-19 10:26:51.975 D/Mono    ( 5282): Unloading image System.Threading.dll [0xab2f7400].
    06-19 10:26:51.975 D/Mono    ( 5282): Image addref System.Threading[0xaec949c0] -> System.Threading.dll[0xb2facb00]: 7
    06-19 10:26:51.975 D/Mono    ( 5282): Config attempting to parse: 'System.Threading.dll.config'.
    06-19 10:26:51.975 D/Mono    ( 5282): Config attempting to parse: '/usr/local/etc/mono/assemblies/System.Threading/System.Threading.config'.
    06-19 10:26:51.975 D/Mono    ( 5282): Assembly Ref addref SQLite-net[0xad9e9dc0] -> System.Threading[0x9dfec5a0]: 5
    06-19 10:26:51.983 D/Mono    ( 5282): Assembly Ref addref SQLite-net[0xad9e9dc0] -> SQLitePCLRaw.batteries_v2[0xad9e9d00]: 2
    06-19 10:26:51.984 D/Mono    ( 5282): Assembly Ref addref SQLitePCLRaw.batteries_v2[0xad9e9d00] -> SQLitePCLRaw.provider.e_sqlite3[0xad9e9e20]: 2
    06-19 10:26:51.984 D/Mono    ( 5282): Assembly Ref addref SQLitePCLRaw.provider.e_sqlite3[0xad9e9e20] -> SQLitePCLRaw.core[0xad9e9f40]: 3
    06-19 10:26:51.985 D/Mono    ( 5282): Assembly Ref addref SQLitePCLRaw.batteries_v2[0xad9e9d00] -> SQLitePCLRaw.core[0xad9e9f40]: 4
    06-19 10:26:51.992 D/Mono    ( 5282): DllImport attempting to load: 'e_sqlite3'.
    06-19 10:26:51.994 D/Mono    ( 5282): DllImport error loading library '/storage/emulated/0/Android/data/LoginSystem.Android/files/.__override__/libe_sqlite3': 'dlopen failed: library "/data/app/LoginSystem.Android-1/lib/x86//storage/emulated/0/Android/data/LoginSystem.Android/files/.__override__/libe_sqlite3" not found'.
    06-19 10:26:51.995 D/Mono    ( 5282): DllImport error loading library '/storage/emulated/0/Android/data/LoginSystem.Android/files/.__override__/libe_sqlite3.so': 'dlopen failed: library "/data/app/LoginSystem.Android-1/lib/x86//storage/emulated/0/Android/data/LoginSystem.Android/files/.__override__/libe_sqlite3.so" not found'.
    06-19 10:26:51.995 D/Mono    ( 5282): DllImport error loading library '/system/lib/libe_sqlite3': 'dlopen failed: library "/data/app/LoginSystem.Android-1/lib/x86//system/lib/libe_sqlite3" not found'.
    06-19 10:26:51.996 D/Mono    ( 5282): DllImport error loading library '/system/lib/libe_sqlite3.so': 'dlopen failed: library "/data/app/LoginSystem.Android-1/lib/x86//system/lib/libe_sqlite3.so" not found'.
    06-19 10:26:51.996 D/Mono    ( 5282): DllImport error loading library 'libe_sqlite3': 'dlopen failed: library "/data/app/LoginSystem.Android-1/lib/x86/libe_sqlite3" not found'.
    06-19 10:26:51.999 D/Mono    ( 5282): DllImport loaded library 'libe_sqlite3.so'.
    06-19 10:26:52.000 D/Mono    ( 5282): DllImport searching in: 'e_sqlite3' ('libe_sqlite3.so').
    06-19 10:26:52.000 D/Mono    ( 5282): Searching for 'sqlite3_libversion_number'.
    06-19 10:26:52.007 D/Mono    ( 5282): DllImport searching in: 'e_sqlite3' ('libe_sqlite3.so').
    06-19 10:26:52.007 D/Mono    ( 5282): Searching for 'sqlite3_open_v2'.
    06-19 10:26:52.028 D/Mono    ( 5282): DllImport searching in: 'e_sqlite3' ('libe_sqlite3.so').
    06-19 10:26:52.028 D/Mono    ( 5282): Searching for 'sqlite3_busy_timeout'.
    06-19 10:26:52.036 D/Mono    ( 5282): Unloading image System.Reflection.dll [0xab2fab00].
    06-19 10:26:52.036 D/Mono    ( 5282): Image addref System.Reflection[0xaec950e0] -> System.Reflection.dll[0x9d005400]: 8
    06-19 10:26:52.036 D/Mono    ( 5282): Config attempting to parse: 'System.Reflection.dll.config'.
    06-19 10:26:52.036 D/Mono    ( 5282): Config attempting to parse: '/usr/local/etc/mono/assemblies/System.Reflection/System.Reflection.config'.
    06-19 10:26:52.036 D/Mono    ( 5282): Assembly Ref addref SQLite-net[0xad9e9dc0] -> System.Reflection[0x9dfec600]: 6
    06-19 10:26:52.037 D/Mono    ( 5282): Unloading image System.Linq.dll [0xab2fab00].
    06-19 10:26:52.038 D/Mono    ( 5282): Image addref System.Linq[0xaec950e0] -> System.Linq.dll[0x9d007200]: 7
    06-19 10:26:52.038 D/Mono    ( 5282): Config attempting to parse: 'System.Linq.dll.config'.
    06-19 10:26:52.038 D/Mono    ( 5282): Config attempting to parse: '/usr/local/etc/mono/assemblies/System.Linq/System.Linq.config'.
    06-19 10:26:52.038 D/Mono    ( 5282): Assembly Ref addref SQLite-net[0xad9e9dc0] -> System.Linq[0x9dfec900]: 5
    06-19 10:26:52.169 E/Surface ( 5282): getSlotFromBufferLocked: unknown buffer: 0x9bd87280
    InspectorDebugSession(9): HandleTargetEvent: UnhandledException
    06-19 10:27:04.139 I/art     ( 5282): Thread[2,tid=5287,WaitingInMainSignalCatcherLoop,Thread*=0xab32c500,peer=0x12c770a0,"Signal Catcher"]: reacting to signal 3
    06-19 10:27:04.224 I/art     ( 5282): Wrote stack traces to '/data/anr/traces.txt'
    

    我建议在Medicine_事件类声明中添加一个引用与其关联的药物的ForeignKey

    public class Medicine_Incident : Medicine
    {
        // Whatever properties you have already defined
    
        ...
    
        // This is your link to your medicine PrimaryKey
        public int MedicineId { get; set; }
    }
    
    如果为了方便起见,希望在Medicine类声明中保留ICollection,请在其上抛出IgnoreAttribute,如下所示:

    public class Medicine 
    {
        // Whatever other stuff you have declared
    
        ...
    
        [Ignore]
        public virtual ICollection<Medicine_Incident> Medicine_Incident { get; set; }
    }
    
    公共级医学
    {
    //你申报的其他东西
    ...
    [忽略]
    公共虚拟ICollection\u事件{get;set;}
    }
    

    这确保了SQLite不会尝试为ICollection类型创建列,因为它不知道如何创建。

    请包含异常堆栈traceAlright刚刚创建的,谢谢!这是应用程序的输出,而不是堆栈跟踪每次有人用下划线代替驼峰来表示c#,小猫痛苦地死去看着这个链接问题与sqlite有关:好吧,有道理,但我怎么才能替换这一行呢?医学.医学事件.增补(医学公司);var med_inc=(医疗事件)绑定上下文;var medicine=(medicine)绑定上下文;我很乐意回答更多的问题,但在评论中这样做在StackOverflow中是不受欢迎的。如果你有一个全新的问题要问,请随意开始一个新的问题,充分考虑你所面临的问题。我理解。非常感谢,tho!:)
    public class Medicine_Incident : Medicine
    {
        // Whatever properties you have already defined
    
        ...
    
        // This is your link to your medicine PrimaryKey
        public int MedicineId { get; set; }
    }
    
    public class Medicine 
    {
        // Whatever other stuff you have declared
    
        ...
    
        [Ignore]
        public virtual ICollection<Medicine_Incident> Medicine_Incident { get; set; }
    }