Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating Nuget caused Exception Unhandled: System.TypeLoadException

I'm starting a new master xamarin page for testing purposes and updated the nuget packages for the xamarin.android.support and xamarin.forms version. Afterwards, my program gets the exception:

The LoadApplication gets the exception error:

    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
like image 363
Joey Avatar asked Sep 20 '19 17:09

Joey


2 Answers

Downgrade xamarin.forms and xamarin.forms.maps to v4.1.0.778454 in all projects.

I did it and worked perfectly

like image 64
Paulo Lana Avatar answered Nov 07 '22 15:11

Paulo Lana


The issue is tracked on github and the issue only triggers only Visual Studio 2017 users. If you compile the app with Visual Studio 2019, the app runs fine with Xamarin.Forms 4.2.0.815419 (4.2.0 Service Release 2).

This is caused by a Mono change that made it into Xamarin.Android in VS2019.

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.

The Xamarin.Forms team tries now to implement Stack and Queue internally in XF code for VS 2017 Compatibility.

Until this is merged, the last Xamarin.Forms bit are compiled with VS2017 and work so fine with VS2017.

like image 31
magicandre1981 Avatar answered Nov 07 '22 15:11

magicandre1981