我们目前正在使用
EqualityComparer<TKey>.Default
作为初始化通用字典的默认方法。但是,当字典的键为type时,它在xamarin.ios上崩溃,并出现以下错误
int
(但在我尝试过的许多其他平台上工作):
正在尝试JIT编译方法
Lucene.Net.Support.LurchTable2<Lucene.Net.Facet.Taxonomy.FacetLabel, Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyReader/Int32Class>:InternalInsert<Lucene.Net.Support.LurchTable2/Add2Info<Lucene.Net.Facet.Taxonomy.FacetLabel, Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyReader/Int32Class>> (int,Lucene.Net.Facet.Taxonomy.FacetLabel,int&,Lucene.Net.Support.LurchTable/Add2Info<Lucene.Net.Facet.Taxonomy.FacetLabel, Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyReader/Int32Class>)
在仅AOT模式下运行时。参见
https://developer.xamarin.com/guides/ios/advanced_topics/limitations/
更多信息。
在lucene.net.support.lurchtable2[t key,t value]处插入[t](tkey key,t&value)<0x2570f48+0x000e0>在<063e095c95d945a4ace32ab83d127eb 2ae0fea9ea4ea4aef83bf2e9713bb8ea>:0在(wrapper unknown)system.object.gsharedvt_in()处,在lucene.net.support.lurchtable2[tkey,tvalue]处插入。(tkey key,tvalue addvalue,lucene.net.support.keyvalueupdate2[tkey,tvalue]fnupdate)<0x232824c+0x0013b>in<063e095c95d945a4ace32ab83d122eb 2ae0fea9ea4eaaef83bf2e9713bb8ea>:0 at lucene.net.facet.taxonomy.lruhashmap2[tkey,tvalue].put(tkey key,tvalue value)<0x2c487f8+0x0015b>位于<79d3a7b905954d0993025c09c5d087ce 2ae0fea9ea4eaaef83bf2e9713bb8ea>:0,位于lucene.net.facet.taxonomy.directory.directoryTaxonomyReader.getordinal(lucene.net.facet.taxonomy.facettelabel cp)<0x2c51970+0x0019b>位于<79d3a7b905954d0993025c09c5d087ce 2ae0fea9ea4ea4eaace83bf832e9713bb8ea>:0位于lucene.net.facet.taxonomy.int32taxonomyfaces.gettopchildren(system.int32 topn,system.string dim,system.string[]path)<0x2c481dc+0x008f>位于<79d3a7b905954d0993025c09c5d087ce 2ae0fea9ea4eaaef83bf2e9713bb8ea>:0位于login.mymb.lucene.client.luceneartiolisearcher.getlistaarticolxricercavanzataconricercasemplice(system.collections.generic.list1[t]listparametri)<0x224add0+0x001bb>在<8f49891e0f546e185aba7424d294ef7 2ae0fea9ea4eaaef83bf2e9713bb8ea>:0在login.mymb.lucene.client.lucenearticolisearcher.getlistaarticolcorcasemplice(system.coll)中sections.generic.list1[t]listparametri)<0x224afbc+0x0009f>in<8f49891e0f546e185aba7424d294ef7 2ae0fea9ea4eaaef83bf2e9713bb8ea>:0 at mymb.forms.ricercalucene.ricercaarticololucene.getlistaarticolixricercassemplice(login.mymb.interface.iambiente ambiente,login.mymb.lucene.client.lucentearticolisearcher las,system.collections.generic.list`1[t]listparametri,system.boolean isabilitaricercabarcode)<0xe47fc0+0x000e7>in:0………………………
在连接处
https://docs.microsoft.com/it-it/xamarin/ios/internals/limitations
,我发现问题的原因(我想是…):
值类型作为字典键使用值类型作为
Dictionary<TKey, TValue>
键有问题,因为默认字典构造函数试图使用
EqualityComparer<Tkey>默认值。
.
EqualityComparer<Tkey>默认值。
反过来,尝试使用反射来实例化实现
IEqualityComparer<TKey>
接口。这适用于引用类型(因为反射+创建一个新的类型步骤被跳过),但是对于值类型,一旦您尝试在设备上使用它,它会很快崩溃和烧毁。
解决方法:
手动执行
IEqualityComparer<tkey>
新类型中的接口,并将该类型的实例提供给
字典<tkey,tvalue>
(
IEqualityComparer<tkey>
)建造师。
问题
是否有内置的跨平台方式来创建默认
IEqualityComparer<int>
是吗?我尽量避免上这样的课
private class Int32EqualityComparer : IEqualityComparer<int>
{
bool IEqualityComparer<int>.Equals(int x, int y)
{
return x.Equals(y);
}
int IEqualityComparer<int>.GetHashCode(int obj)
{
return obj.GetHashCode();
}
}
只是为了避开这个错误。