Xamarin.Forms icon indicating copy to clipboard operation
Xamarin.Forms copied to clipboard

[Bug] Android: ReflectionTypeLoadException and TypeLoadException in Release Mode

Open ManuLin opened this issue 3 years ago • 0 comments

Description

In our Xamarin.Forms Android application we are occassionally observing ReflectionTypeLoadExceptions and TypeLoadExceptions with the following stack trace:

Exception of type 'System.Reflection.ReflectionTypeLoadException' was thrown. Could not set up parent class, due to: VTable setup of type Microsoft.EntityFrameworkCore.DbContext failed assembly:Microsoft.EntityFrameworkCore.dll

System.TypeLoadException: Could not set up parent class, due to: Could not set up parent class, due to: VTable setup of type Microsoft.EntityFrameworkCore.DbContext failed assembly:Microsoft.EntityFrameworkCore.dll type:DbContext member:(null)

We are using the most recent version of Xamarin Forms (5.0.0.2515) and also the highest possible version of AndroidX packages which are compatible therewith. It is important to note that the exception can only be observed in release builds, debug builds on the other hand function flawlessly. Moreover, the problem occurrs only when building our application with VS 2022 - in VS 2019, we were not able to reproduce this issue. However, building with VS 2019 is not really an option for us anymore for several reasons.

Did anyone experience a similar issue? The Android linker does not seem be the problem, as the exceptions are also thrown when linking is set to 'None'. Any help is greatly appreciated.

Expected Behavior

No exceptions are thrown.

Actual Behavior

TypeLoadExceptions are being thrown

ManuLin avatar Sep 22 '22 07:09 ManuLin