Closed DerGary closed 3 years ago
I'have the same exception.
I also have this. It's a major problem for us.
I have the same exception. Everything is fine when using 3.0.x.
It seems like xamarin.ios is picking the netstandard2.1 version of microsoft.extensions.dependencyinjection 3.1.x. When using netstandard2.1, the IL_EMIT constant is set and the DI code switches to ILEmitResolverBuilder instead of ExpressionResolverBuilder. ILEmit is not supported on ios, this is why the exception is raised.
3.0.x does not support netstandard2.1, and when the targetFramework is netstandard2.0, the ILEmitBackend is not used. This is why everything is ok when using 3.0.x.
Maybe IL_EMIT should not be set for netstandard2.1, just like for netstandard2.0 ?
Triage: It should be possible to detect this with the runtime capability API and have DI switch from IL Emit mode to Reflection when IL Emit is not available. Marking for transfer to runtime for 5.0 consideration.
I couldn't figure out the best area label to add to this issue. Please help me learn by adding exactly one area label.
The reason we are hitting in Xamarin is because from
we are hitting line 64.
IsDynamicCodeCompiled is only available in netcoreapp. When Xamarin moves to .NET Core runtime, this issue would get fixed.
The issue seems to be gone when using version 3.1.11 of 'Microsoft.Extensions.DependencyInjection'
Is this issue still relevant?
The issue is gone, but if we don't know what was causing it and what has changed that fixed it, it'll come back. Also, there should be some kind of unit test, to guarantee that xamarin.ios will continue to be properly supported in the future.
This issue is fixed if you use the latest bits.
Using version '4.2.0.910310' of package 'Xamarin.Forms'
Older versions of Xamarin forms use the netstandard2.0
asset from Microsoft.Extensions.DependencyInjection
. When using the netstandard2.1
version of the library:
it checks if (RuntimeFeature.IsDynamicCodeCompiled)
. If ILEmit
is not supported on the platform (which it shouldn't be on iOS as far as I know), RuntimeFeature.IsDynamicCodeCompiled
will return false
. Which means we will never try to use ILEmit.
Closing. If you see this again with the latest versions, feel free to re-open.
Describe the bug
I can't really describe why the bug is occuring Because I don't understand where in the code exactly it occurs. But I try my best. So I have a Xamarin.IOs app with different Pages. When I navigate to a page that creates a couple of ViewModels (that are using Dependency Injection) then navigate back and then navigate to this page again, then an exception is raised in an unobserved task that seems to be outside my own code. I can't debug to the exception only after it happened the UnobservedException call back is triggered and there i could log the exception. It looks like this:
To Reproduce
Steps to reproduce the behavior:
Expected behavior
No Exception is thrown (it works on 3.0.x)