随机 System.TypeLoadException

问题描述

我正在使用最新的 Visual Studio 2019 更新构建 Xamarin Android 应用。 在某些设备上,我遇到了一些我不明白的异常,因为在大多数设备上似乎都很好。

例外 1:

System.TypeLoadException: Could not resolve type with token 010000a0 from typeref (expected class 'System.St' in assembly 'mscorlib,Version=2.0.5.0,Culture=neutral,PublicKeyToken=7cec85d7bea7798e')
System.Net.Http.httpclienthandler..ctor () [0x00000] in <29982df1e97049f5afd4cab6d3aaf93d>:0
ModernHttpClient.NativeMessageHandler..ctor (System.Boolean throwOncaptivenetwork,System.Boolean customSSLVerification,ModernHttpClient.NativeCookieHandler cookieHandler) [0x00033] in <51795dd1dbb344bdacae7208f448a6b3>:0

例外 2:

System.TypeLoadException: Could not set up parent class,due to: Could not load type of field 'System.Net.Http.httpclienthandler:<DangerousAcceptAnyServerCertificateValidator>k__backingField' (2) due to: Could not resolve type with token 0100003b from typeref (expected class 'System.Security.Cryptography.X509Certificates.X509Chais' in assembly 'System,PublicKeyToken=7cec85d7bea7798e') assembly:System,PublicKeyToken=7cec85d7bea7798e type:System.Security.Cryptography.X509Certificates.X509Chais member:(null) assembly:System.Net.Http.dll type:httpclienthandler member:(null)

例外 3:

System.TypeInitializationException: Invalid IL code in System.Net.Http.httpclienthandler/<>c:.cctor (): IL_000a: calli 0x9628021e
ModernHttpClient.NativeMessageHandler..ctor (System.Boolean throwOncaptivenetwork,ModernHttpClient.NativeCookieHandler cookieHandler) [0x00033] in <51795dd1dbb344bdacae7208f448a6b3>:0
ModernHttpClient.NativeMessageHandler..ctor () [0x00000] in <51795dd1dbb344bdacae7208f448a6b3>:0

例外 4:

System.TypeLoadException: Could not resolve type with token 01000071 from typeref (expected class 'System.Net.Http.HttpRequestException' in assembly 'System.Net.Http,Version=4.0.0.0,PublicKeyToken=b03f5f7f11d50a3a') assembly:System.Net.Http,PublicKeyToken=b03f5f7f11d50a3a type:System.Net.Http.HttpRequestException member:(null)

似乎在某些设备上找不到来自“System.Net.Http”的某些程序集或类。我尝试将“AndroidLinkMode”从“SdkOnly”更改为“None”并检索到更大的 APK 文件,但问题仍然存在。

编辑: 我正在使用 Azure Dev Ops 部署的 NuGet 包(与我的计算机不同的代理)。 Visual Studio 是最新的,所有包引用都具有相同的版本。

解决方法

我可以通过在项目属性的“Android 选项”下启用“将程序集捆绑到本机代码”来解决这个问题,希望如此。