runtime: [Android] Throws runtime error in `mscorlib`, expected class `System.Runtime.CompilerServices.ValueTaskAwaiter1`
Description
I am unable to use ably package with a dependency on System.Threading.Channels
(the error might also have origin from System.Threading.Tasks.Extensions
/System.Runtime.CompilerServices.Unsafe
assembly) , throws below runtime exception on MAUI android.
Throws a runtime error while trying to run on android =>
System.TypeLoadException: 'Could not load type of field 'IO.Ably.Realtime.Workflow.RealtimeWorkflow+d__36:<>u__2' (11) due to:
Could not resolve type with token 010000ba from typeref (expected class 'System.Runtime.CompilerServices.ValueTaskAwaiter1'
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.Runtime.CompilerServices.ValueTaskAwaiter1 member:(null)
It works on a regular net6.0 library, MAUI windows machine, and the latest Xamarin Forms.
I tried all options to disable assembly trimming as per https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/trimming-options?pivots=dotnet-6-0 but the issue still persists and the app throws an error at runtime.
I strongly feel the issue is related to a missing type in mscorlib
same as the one mentioned in https://github.com/dotnet/maui/issues/5078 and https://github.com/dotnet/maui/issues/5142
Steps to Reproduce
- Clone the project from https://github.com/sac-fork/MauiAppAblyDemo
- Build and run it on android emulater ( I used default Pixel 5 - API 33 (API 13 - API 33) )
- Tap on
Click me
button, it will throw above error.
Link to public reproduction project repository
https://github.com/sac-fork/MauiAppAblyDemo
Version with bug
6.0 / 7.0
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
Android API 13 to 33
Did you find any workaround?
No workarounds were found.
Relevant log output
System.TypeLoadException: 'Could not load type of field 'IO.Ably.Realtime.Workflow.RealtimeWorkflow+d__36:<>u__2' (11) due to: Could not resolve type with token 010000ba from typeref (expected class 'System.Runtime.CompilerServices.ValueTaskAwaiter1' 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.Runtime.CompilerServices.ValueTaskAwaiter1 member:(null)
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 20 (6 by maintainers)
Commits related to this issue
- Add more type-forwarders for Xamarin.Android compatibility to mscorlib.dll The legacy Xamarin.Android version of mscorlib.dll differed a bit compared to the .NET Framework mscorlib.dll, mostly becaus... — committed to akoeplinger/runtime by akoeplinger a year ago
- Add more type-forwarders for Xamarin.Android compatibility to mscorlib.dll (#82618) The legacy Xamarin.Android version of mscorlib.dll differed a bit compared to the .NET Framework mscorlib.dll, most... — committed to dotnet/runtime by akoeplinger a year ago
- Add more type-forwarders for Xamarin.Android compatibility to mscorlib.dll (#82618) The legacy Xamarin.Android version of mscorlib.dll differed a bit compared to the .NET Framework mscorlib.dll, most... — committed to akoeplinger/runtime by akoeplinger a year ago
- [release/7.0] Add more type-forwarders for Xamarin.Android compatibility to mscorlib.dll and System.Drawing.Common.dll (#83137) * Add more type-forwarders for Xamarin.Android compatibility to mscorli... — committed to dotnet/runtime by akoeplinger a year ago
@sacOO7 we merged the backport to the release/7.0 branch and is currently targeted for the 7.0.5 release.