Xamarin.forms: [Bug] Android app crashes since updating to Xamarin Forms v4

Created on 20 Sep 2019  ·  56Comments  ·  Source: xamarin/Xamarin.Forms

Since updating to 4.2.0.815419 I now get the following exception thrown at LoadApplication(new App(dbPath, builder)); within MainActivity.cs

I did also try v4.3.0.819712-pre2 in case there was a fix contained.

I will have to rollback to 3.5.0.129452 but I thought it would be useful to log the issue.

Linking is set to None. UWP app does work.

09-25 13:17:14.076 E/mono    ( 5126): 
09-25 13:17:14.076 E/mono    ( 5126): Unhandled Exception:
09-25 13:17:14.076 E/mono    ( 5126): 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)
09-25 13:17:14.076 E/mono    ( 5126):   at (wrapper dynamic-method) System.Object.7(intptr,intptr,intptr)
09-25 13:17:14.076 E/mono    ( 5126):   at (wrapper native-to-managed) System.Object.7(intptr,intptr,intptr)
09-25 13:17:14.076 E/mono-rt ( 5126): [ERROR] FATAL 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)
09-25 13:17:14.076 E/mono-rt ( 5126):   at (wrapper dynamic-method) System.Object.7(intptr,intptr,intptr)
09-25 13:17:14.076 E/mono-rt ( 5126):   at (wrapper native-to-managed) System.Object.7(intptr,intptr,intptr)
high regression Android bug

Most helpful comment

I found that 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.
I think not only Queue but also other classes in Collections.Generic namespace could suffer the same issue.

All 56 comments

From a first glance this does seem like some kind of caching issue. Make sure you updated all the projects to the same version of Xamarin.Forms, then clean the solution. To be sure delete the bin and obj folders from each of the projects as well on the filesystem. Also remove the app from the emulator or device.

Do a rebuild, run and hopefully all should be resolved. Did you try any of these things already?

I found that I had to uninstall any existing 3.0 apps on the phone and re deploy clean and build your solution then should be ok. Could well be hot reload has happened a few times for me so make sure that this is disabled.

Hi @jfversluis these issues actually also occur on devops and appcenter, both areas clean the working area before any build I believe

Searching for this error message it seems to have to do with the Android targeting and support packages. Did you update those as well? Could you provide some more info on what packages are installed exactly with which version and what Android version you are trying to target?

Yes I updated my api level to Andriod 9

On Fri, Sep 20, 2019 at 3:46 PM Gerald Versluis notifications@github.com
wrote:

Searching for this error message it seems to have to do with the Google
targeting and support packages. Did you update those as well? Could you
provide some more info on what packages are installed exactly with which
version and what Android version you are trying to target?


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/xamarin/Xamarin.Forms/issues/7602?email_source=notifications&email_token=ABK34HK3EWZVVCQWHUGBMZLQKTO3PA5CNFSM4IYVWRJKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD7G5L6I#issuecomment-533583353,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABK34HLYSFLSUXVEIB5H67LQKTO3PANCNFSM4IYVWRJA
.

--

Regards
David Buckley
M: 07871 884 546

i having the same issue after update to latest version, in the previous version everything works fine, but when i update the xamarin the error occurs.

Can anyone experiencing this issue please attach a small project that demonstrates this issue? Thanks!

I see someone with the same issue here on SO: https://stackoverflow.com/questions/58032635/updating-nuget-caused-exception-unhandled-system-typeloadexception

It seems to have to do with Maps? Can someone verify this? And what Samantha said, a reproduction would be super awesome!

I have the exact same issue, in both Android and iOS. On Android the app builds and crashes upon start up on iOS the app does not build (when targeting a real device simulator build works fine). I get the error referenced in the Stack overflow link above relating to System.Collections.Generic.Stack`1

The problem does not exist if I revert back to 4.2.0.778463

I am not sure if it is related to maps, but my app does include the Maps nuget package.

I don't use maps, that's occur even in a fresh project

@KennyMack would you be able to put that in a reproduction project and add that here?

I got the same error upgrading to 4.2 SR2.
I tried several suggestions, updated all nuget-packages, but app still crashed.
I started a new blank app (in 4.0), works fine!
Upgraded tot 4.2 SR2, crashed!
Then I updated Visual Studio (16.2.5), and the problem was gone!!

@KennyMack would you be able to put that in a reproduction project and add that here?

I simply created a new empty app and also get a TypeLoadException (but without any details) in VS2017 15.9

image

Then I updated Visual Studio (16.2.5), and the problem was gone!!

with VS2019 I'm also able to compile and run the app without any issue.

@jfversluis Any ideas why it fails for VS2017? Is this a Mono issue with VS2017 15.9?

@jfversluis Here the project, i just create and update the xamarin to version 4.2.0.815419 and app crash when start
https://github.com/KennyMack/ExampleFail

I had the same issue using AppCenter, also using 4.2.0.815419 both iOS and Android builds failed with the same "expected class 'System.Collections.Generic.Stack" message.

I changed the build configuration in AppCenter to use: SDK Version: Xamarin.iOS 12.14 and Xcode version: 10.3.
The problem seems to have gone away now since changing to these settings, on the iOS builds (haven't tried the Android yet).

@KennyMack I pulled down your repro and it all works fine for me

image

@KennyMack I pulled down your repro and it all works fine for me

which VS do you use? The issue only occurs in 2017 and not 2019

@KennyMack I pulled down your repro and it all works fine for me

image

This is strange, in my version does not work.
I'm using visual studio 2017 version 15.9.16.
do I need to update anything else?

My mistake

It does crash for me on VS 2017 :-/

We just moved our build pipeline to start using VS 2019 so I'm poking around internally to see about the above exceptions

I'm having same issue as @dannythomas13 said. Initially my xamarin forms version was 3.4.0.1008975 and when i updated it to 4.2.0.815419 app crashes showing the same issue. Even i tried in blank project it crashes giving same error. My vs is vs enterprise 2017 version 15.9.13.

I'm having same issue as @dannythomas13 and @zimbabirbal said. you can fix it so that it also works with VS2017?

I found that 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.
I think not only Queue but also other classes in Collections.Generic namespace could suffer the same issue.

The iOS build on VS2017 has the same issue. See #7638.

Had the same error on VS 16.0.3, upgraded to latest (16.3.1) and issue is solved. #magic

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.
I think not only Queue but also other classes in Collections.Generic namespace could suffer the same issue.

This is something that the Xamarin.Android team should look at @jonathanpeppers @brendanzagaeski

This started happening because we moved our build servers from VS 2017 to VS 2019 which has newer versions of XA/XI/Mono SDKs. When you build against newer versions of those SDKs those versions will no longer work on older versions.

This is the specific change triggering this exception https://github.com/mono/mono/pull/11511

The next release of 4.2 will be built against VS 2017 so that it can still be used on VS 2017 but 4.3 is going to require you to have at least 16.3

The reason for this is requirement on 4.3 has to do with literally every platform requiring Visual Studio 16 and/or 16.3 to use the latest SDKs

XCode11 requires 16.3
Android 10 requires 16.3 and Android X requires at least 16.2
WinUI requires at least VS 2019 in order to use the most compatible SDKs

Up until now we haven't really needed to build against the newer SDKs but now we have to in order to support the newer frameworks

The next release of 4.2 will be built against VS 2017 so that it can still be used on VS 2017 but 4.3 is going to require you to have at least 16.3

ok, so we will stop using Xamarin.Forms. VS2019 is a no go. Bye. Bye and RIP Xamarin.

@MagicAndre1981 We're still discussing options. We have not yet made the decision to require VS2019 for 4.3.

Would you be willing to share why VS2019 is a "no go"? What is your timeline for upgrading?

Thanks!

Would you be willing to share why VS2019 is a "no go"?

because of the broken UI (horrible modal Start Window, this ruined "New Project dialog" and the notification icon at buttom where I always overlook it). VS2019 repeats the VS2012 desaster

There is also a crash on iOS. Is it also caused by the older version of VS for Mac? Because for me this is failing on Azure DevOps where I have selected macOS X Mojave 10.14 as an agent for a build.

Seconding that this issue is affecting build pipelines on DevOps using macOS 10.14. Is there any short term fix or are we stuck waiting for a new 4.2.X version?

Hi there,
we need some help and advice.

I need to upgrade to 4.2.0.815419 that fixes an issue with image uri not working in previous versions.
I was to deliver to a client today but could not.
I would like to avoid reverting to an very old version of 4.

However all day trying to make ios build against 4.2.0.815419 getting
"Failed to resolve "System.Collections.Generic.Stack`1" . Tried all sorts of things... and getting different errors that I m not mentioning here as it might confuse things.

Something definitely changed with 4.2.0.815419 and we cannot build anymore on azure pipeline on iOS.

my last working build was using mono 5_16 with 4.1.0.709244

any suggestions ?

I was having the same problem.
I installed Xamarin Essentials and nuget asked to upgrade Xamarin to version 4.2.0.815419.
I went back to version 4.2.0.778463 and it went back to work

I'm seeing the same problem as @developer9969 and @oliveiraugusto with the 4.2.0.848062 version.

MTOUCH : error MT2002: Failed to resolve "System.Collections.Generic.Stack`1" reference from "mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e"

I'm running the iOS build with the below scritp, specifying MONO SDK version and Xcode

/bin/bash -c "sudo $AGENT_HOMEDIRECTORY/scripts/select-xamarin-sdk.sh 5_18_1"
/bin/bash -c "sudo xcode-select -s /Applications/Xcode_10.2.1.app/Contents/Developer"

Any workarounds?

HI Team
I am also getting the same issue, is there any fix that we can expect to work xamarin forms on VS 2017?

@ryanmendoza To fix the iOS devops build, you need to use xCode 11 and Xamarin sdk 6_4_0. Add build task "Use .NET Core" to the pipeline using version 3.0.100.

@ryanmendoza

Seconding that this issue is affecting build pipelines on DevOps using macOS 10.14. Is there any short term fix or are we stuck waiting for a new 4.2.X version?

There is actually a new version now, does that fix things for you?

This should be resolved in the latest versions of Xamarin.Forms published on NuGet. Thank you!

This should be resolved in the latest versions of Xamarin.Forms published on NuGet.

which version/build number? How long will XF work for VS2017 users?

4.2.0.848062 and 4.3.0.851321-pre3 are both compatible with VS2017.

I can confirm that using the latest builds (mentioned above) has resolved the reported issue without the need to upgrade / change your existing tooling.

4.2.0.848062 ... compatible with VS2017.

thanks, I can confirm this.

There is no point in getting new versions of Xamarin.Forms to work with old tooling. People who want to use old tooling can still use old versions of Xamarin.Forms. Needing to support old tooling would be a drag on development in a repo that already has too many drags on development.

I got same issue on Xamarin.Forms.iOS version 4.3.0.991211 on MacOS Mojave

@samhouts this issue is closed, but the problem still exists...Where is the official solution, or give to us at least the working workaround to fix this issue, please?

Look at build log in Azure DevOps:
image

_Project type - Xamarin.iOS
Mono - 5.12.0
XCode - 10.2.1_

my .yaml configuration in Azure DevOps

@beylkhanovdamir what version of Xamarin.Forms are you using? This should not happen anymore after the earlier mentioned versions

@jfversluis It still happens to me too (Xamarin.Forms.iOS version 4.3.0.991211)

@Sonic3R you are using VS2017 on Windows? VSMac? Can you give some more details?

Visual Studio for Mac, version 8.3

@jfversluis you can look at my .yaml configuration in DevOps

p.s. I'm using '_macOS-latest_' vmImage and XF version below
image

@beylkhanovdamir did you see this comment: https://github.com/xamarin/Xamarin.Forms/issues/7602#issuecomment-537847507

I see you're setting the SDK version manually and you're using Xcode 10, you might want to look into using current versions together with the newest Forms version.

@Sonic3R could you share a little bit more about what errors you are seeing in VSMac when building? What version of Xcode are you using?

Guys i FOUND that its hot reload gets renabled disable hot reload and your
app will be fine.

On Tue, Dec 3, 2019 at 12:47 PM Gerald Versluis notifications@github.com
wrote:

@beylkhanovdamir https://github.com/beylkhanovdamir did you see this
comment: #7602 (comment)
https://github.com/xamarin/Xamarin.Forms/issues/7602#issuecomment-537847507

I see you're setting the SDK version manually and you're using Xcode 10,
you might want to look into using current versions together with the newest
Forms version.

@Sonic3R https://github.com/Sonic3R could you share a little bit more
about what errors you are seeing in VSMac when building?


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/xamarin/Xamarin.Forms/issues/7602?email_source=notifications&email_token=ABK34HN56WUZL3KRXAAKWVDQWZIPTA5CNFSM4IYVWRJKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFZIBKQ#issuecomment-561152170,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ABK34HM2BQTF5PHNEBQVEFDQWZIPTANCNFSM4IYVWRJA
.

--

Regards
David Buckley
M: 07871 884 546

@jfversluis

did you see this comment: #7602 (comment)

yes, I saw, but I can't, because we have a project where target FW is .netstandard 2.0 (i.e. not 2.1 which is compatible with .net core 3.0), and in this case, I will get a lot of compilation errors.
But perhaps, for now, it's really the last way to fix this issue

Hi - Getting the below error message on Visual studio 2017 supports Xamarin.iOS 12.4.0.64. Someone please assist us on this as it blocked our complete deployment process now.

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(795,3): error MT2002: Failed to resolve "System.Collections.Generic.Stack`1" reference from "mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e"

This error message comes ONLY after paring with mac which has same Xamarin.iOS, latest xCode and mono 5.18.

Thanks in advance

@ryanmendoza To fix the iOS devops build, you need to use xCode 11 and Xamarin sdk 6_4_0. Add build task "Use .NET Core" to the pipeline using version 3.0.100.

What does this even mean? I'm pretty confused by this, do you have example YAML you could share?

What am I building with .netcore task? The iOS project.. how? I clearly am missing something.

Was this page helpful?
0 / 5 - 0 ratings