【问题标题】:System.NotSupportedException XamarinSystem.NotSupportedException Xamarin
【发布时间】:2017-06-19 14:20:31
【问题描述】:

我有一个包含 3 步注册流程的应用,

  1. 姓名、电子邮件、密码(在 signup_vm 内);
  2. 用户详细信息(在 User_ProfileINC_vm 内);
  3. 药物摄入量(在 UserMedicineINC_vm 内)。

一旦我导航到 3),我就能通过 1) 和 2) - 我看到页面的 UI,但突然出现“未处理的异常”弹出框。

我在调试输出中遇到的错误:

System.NotSupportedException: Don't know about System.Collections.Generic.ICollection`1[LoginSystem.Models.Medicine]

我认为这是因为我的 Medicine 类中有这行代码(在模型文件夹中):

public virtual ICollection<Medicine_Incident> Medicine_Incident { get; set; }  

而这个 Medicine_Incident 只是另一个继承 Medicine 的类,如下所示:

public class Medicine_Incident : Medicine

*Medicine and Medicine_Incident 定义了一些字段,例如:

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'

【问题讨论】:

  • 请包含异常堆栈跟踪
  • 好的,谢谢!
  • 这是 App 输出,而不是堆栈跟踪
  • 每次有人在 c# 中使用下划线而不是骆驼套时,小猫就会痛苦地死去
  • 看这个链接问题与sqlite有关:forums.xamarin.com/discussion/18548/…

标签: c# exception xamarin exception-handling icollection


【解决方案1】:

我建议在 Medicine_Incident 类声明中添加一个 ForeignKey 来引用它所关联的 Medicine。

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; }
}

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

【讨论】:

  • 好的,有道理,但我怎么能替换这条线?医学.Medicine_Incident.Add(med_inc);
  • var med_inc = (Medicine_Incident)BindingContext;
  • var Medicine = (Medicine)BindingContext;
  • 我很乐意回答更多问题,但在 StackOverflow 中不赞成在 cmets 中这样做。如果您有一个全新的问题要问,请随时提出一个新问题,并详细说明您所面临的问题。
  • 我明白了。非常感谢! :)
猜你喜欢
  • 2016-08-21
  • 2015-07-24
  • 2020-10-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多