更新Nuget导致异常未处理:System.TypeLoadException。

7

我为了测试目的开始一个新的 Xamarin 页面,并更新了 xamarin.android.support 和 xamarin.forms 版本的 NuGet 包。之后,我的程序出现以下异常:

LoadApplication 出现异常错误:

    base.OnCreate(savedInstanceState);
    global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
    LoadApplication(new App());


Unhandled Exception:

System.TypeLoadException: Could not load type of field 'Xamarin.Forms.Platform.Android.RendererPool:_freeRenderers' (0) due to: Could not resolve type with token 01000275 from typeref (expected class 'System.Collections.Generic.Stack`1' in assembly 'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e') assembly:mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e type:System.Collections.Generic.Stack`1 member:(null) occurred
3个回答

10

将所有项目中的xamarin.forms和xamarin.forms.maps降级至v4.1.0.778454。

我这样做了,效果完美。


1
升级只为了降级回去,虽然可行,谢谢。有没有其他解决此问题的方法? - Joey
1
Xamarin.Forms和Xamarin.Forms.Maps都在版本4.2.0.778463上为我工作,而“最新稳定版”4.2.0.815419则不行。 - Joey
可以确认:最新的“稳定”版本 4.2.0.815419 对我产生了完全相同的问题。降级到上面提到的版本(虽然我没有使用地图)解决了问题。 这就是所谓的“稳定”。我觉得他们现在应该已经解决了这种问题。 - wislon
这真的很有帮助,谢谢。我只是想知道 Visual Studio 版本如何影响它,因为显然它在 VS 2019 中可以工作,参见 https://dev59.com/fLbna4cB1Zd3GeqPa3Lq#58064929。 - CGMan

5
问题在GitHub上被追踪,并且该问题仅会触发Visual Studio 2017用户。如果使用Visual Studio 2019编译应用程序,则可以正常运行Xamarin.Forms 4.2.0.815419 (4.2.0 Service Release 2)

这是由Mono更改引起的,该更改使其进入VS2019中的Xamarin.Android

System.Collections.Generic.Queue is available in

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v1.0\System.dll

and

C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v1.0\mscorlib.dll

It's not available in

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v1.0\mscorlib.dll

So if any dll that relies on Queue is complied with VS2019, and run on VS2017, it will throw exception can't load Queue from mscorlib.

Xamarin.Forms团队现在尝试在XF代码中内部实现堆栈和队列以实现VS 2017兼容性

在此合并之前,最后的Xamarin.Forms位与VS2017一起编译,并且在VS2017上运行良好。


0
启动画面导致崩溃。以下答案解决了我的问题,适用于最新的Xamarin Forms(4.2.0.815419)和VS 2019 Ent(16.3.1)。 在此处查看

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接