列表的动态数据类型导致应用程序崩溃
dynamic datatype for List cause app crash
我在 ViewModel 中有两个列表视图(普通列表和分组列表),在 UI 我想使用一个列表视图。
所以我正在尝试使用动态数据类型进行运行时列表分配。
private dynamic commonList { get; set; }
public dynamic CommonList
{
get
{
return commonList;
}
set
{
commonList = value;
}
}
ItemsGrouped = new ObservableCollection<Grouping<string, ListItem>>(List);
commonList = new ExpandoObject();
commonList = ItemsGrouped;
这工作正常,但是当我试图将另一个列表设置为相同的动态数据类型时,它导致了问题。
Items = new ObservableCollection<ListItem>(List);
commonList = new ExpandoObject();
commonList = Items;
此处应用程序崩溃并出现错误:
dynamic_cast error 2: One or more of the following type_info's has hidden visibility or is defined in more than one translation unit. They should all have public visibility. N10__cxxabiv116__shim_type_infoE, id, N10__cxxabiv117__pbase_type_infoE.
Objective-C exception thrown. Name: NSInvalidArgumentException Reason: *** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]
Native stack trace:
0 CoreFoundation 0x00007fff23c7127e __exceptionPreprocess + 350
1 libobjc.A.dylib 0x00007fff513fbb20 objc_exception_throw + 48
2 CoreFoundation 0x00007fff23d03ab1 _CFThrowFormattedException + 194
3 CoreFoundation 0x00007fff23d06cc6 -[__NSPlaceholderArray initWithObjects:count:].cold.3 + 38
4 CoreFoundation 0x00007fff23c4a1c4 -[__NSPlaceholderArray initWithObjects:count:] + 164
5 CoreFoundation 0x00007fff23c5f6d4 +[NSArray arrayWithObjects:count:] + 52
6 CRMM.iOS 0x0000000100c4b280 xamarin_convert_managed_to_nsarray_with_func + 464
7 CRMM.iOS 0x0000000100c4da18 xamarin_managed_string_array_to_nsarray + 40
8 CRMM.iOS 0x0000000100c4dafc xamarin_managed_array_to_nsarray + 124
9 CRMM.iOS 0x0000000100c498be _ZL33xamarin_marshal_return_value_implP9_MonoTypePKcP10MonoObjectbP11_MonoMethodP17MethodDescriptionPj + 558
10 CRMM.iOS 0x0000000100c4963a xamarin_marshal_return_value + 106
11 CRMM.iOS 0x0000000100c595bb _ZL20marshal_return_valuePvPKcmS_P9_MonoTypebP11_MonoMethodP17MethodDescriptionPj + 1915
12 CRMM.iOS 0x0000000100c50fe0 xamarin_invoke_trampoline + 7984
13 CRMM.iOS 0x0000000100c58adb xamarin_arch_trampoline + 107
14 CRMM.iOS 0x0000000100c59ce2 xamarin_x86_64_common_trampoline + 118
15 UIKitCore 0x00007fff48257490 -[UITableView _updateIndexTitlesFromDataSource] + 149
16 UIKitCore 0x00007fff4825756f -[UITableView _updateIndex] + 165
17 CRMM.iOS 0x0000000100c59e69 xamarin_dyn_objc_msgSend + 217
18 ??? 0x0000000108d10a0a 0x0 + 4442884618
Xamarin 不支持 dynamic
。
这不一定是 Xamarin 的限制,而是本机平台的限制。
例如,iOS 要求其应用程序提前 (AOT) 编译;运行时无法生成代码。这是 Apple 的一项安全要求,旨在防止应用程序在运行时在您的 phone 上生成恶意代码。
有关详细信息,请参阅官方 Microsoft 文档:
https://docs.microsoft.com/xamarin/ios/internals/limitations#no-dynamic-code-generation
我在 ViewModel 中有两个列表视图(普通列表和分组列表),在 UI 我想使用一个列表视图。 所以我正在尝试使用动态数据类型进行运行时列表分配。
private dynamic commonList { get; set; }
public dynamic CommonList
{
get
{
return commonList;
}
set
{
commonList = value;
}
}
ItemsGrouped = new ObservableCollection<Grouping<string, ListItem>>(List);
commonList = new ExpandoObject();
commonList = ItemsGrouped;
这工作正常,但是当我试图将另一个列表设置为相同的动态数据类型时,它导致了问题。
Items = new ObservableCollection<ListItem>(List);
commonList = new ExpandoObject();
commonList = Items;
此处应用程序崩溃并出现错误:
dynamic_cast error 2: One or more of the following type_info's has hidden visibility or is defined in more than one translation unit. They should all have public visibility. N10__cxxabiv116__shim_type_infoE, id, N10__cxxabiv117__pbase_type_infoE.
Objective-C exception thrown. Name: NSInvalidArgumentException Reason: *** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0] Native stack trace: 0 CoreFoundation 0x00007fff23c7127e __exceptionPreprocess + 350 1 libobjc.A.dylib 0x00007fff513fbb20 objc_exception_throw + 48 2 CoreFoundation 0x00007fff23d03ab1 _CFThrowFormattedException + 194 3 CoreFoundation 0x00007fff23d06cc6 -[__NSPlaceholderArray initWithObjects:count:].cold.3 + 38 4 CoreFoundation 0x00007fff23c4a1c4 -[__NSPlaceholderArray initWithObjects:count:] + 164 5 CoreFoundation 0x00007fff23c5f6d4 +[NSArray arrayWithObjects:count:] + 52 6 CRMM.iOS 0x0000000100c4b280 xamarin_convert_managed_to_nsarray_with_func + 464 7 CRMM.iOS 0x0000000100c4da18 xamarin_managed_string_array_to_nsarray + 40 8 CRMM.iOS 0x0000000100c4dafc xamarin_managed_array_to_nsarray + 124 9 CRMM.iOS 0x0000000100c498be _ZL33xamarin_marshal_return_value_implP9_MonoTypePKcP10MonoObjectbP11_MonoMethodP17MethodDescriptionPj + 558 10 CRMM.iOS 0x0000000100c4963a xamarin_marshal_return_value + 106 11 CRMM.iOS 0x0000000100c595bb _ZL20marshal_return_valuePvPKcmS_P9_MonoTypebP11_MonoMethodP17MethodDescriptionPj + 1915 12 CRMM.iOS 0x0000000100c50fe0 xamarin_invoke_trampoline + 7984 13 CRMM.iOS 0x0000000100c58adb xamarin_arch_trampoline + 107 14 CRMM.iOS 0x0000000100c59ce2 xamarin_x86_64_common_trampoline + 118 15 UIKitCore 0x00007fff48257490 -[UITableView _updateIndexTitlesFromDataSource] + 149 16 UIKitCore 0x00007fff4825756f -[UITableView _updateIndex] + 165 17 CRMM.iOS 0x0000000100c59e69 xamarin_dyn_objc_msgSend + 217 18 ??? 0x0000000108d10a0a 0x0 + 4442884618
Xamarin 不支持 dynamic
。
这不一定是 Xamarin 的限制,而是本机平台的限制。
例如,iOS 要求其应用程序提前 (AOT) 编译;运行时无法生成代码。这是 Apple 的一项安全要求,旨在防止应用程序在运行时在您的 phone 上生成恶意代码。
有关详细信息,请参阅官方 Microsoft 文档: https://docs.microsoft.com/xamarin/ios/internals/limitations#no-dynamic-code-generation