Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PlatformNotSupportedException in iOS Release build only #9682

Closed
rlasker-trimble opened this issue Sep 22, 2020 · 7 comments
Closed

PlatformNotSupportedException in iOS Release build only #9682

rlasker-trimble opened this issue Sep 22, 2020 · 7 comments
Labels
iOS Issues affecting iOS support The issue is related to support
Milestone

Comments

@rlasker-trimble
Copy link

When running Xamarin iOS with EF Core release builds of iOS crash if you attempt to use the DbContext. App center logs two exceptions the first silently in unhandled exceptions handler the second crashes the app when attempting to use the context. Code works fine in Android or if the Debug version of the code is used.

Using Xamarin.Forms version 4.8.01451

Logged using the exception handlers in AppDelegate:
ILEmitResolverBuilder.BuildTypeNoCache (Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite callSite)
System.PlatformNotSupportedException: Operation is not supported on this platform.

Exception from using context:
Enumerable.Single[TSource] (System.Collections.Generic.IEnumerable1[T] source, System.Func2[T,TResult] predicate)
System.TypeInitializationException: Sequence contains no matching element

This appears to be the specific reason for the issue but there is no work around or resolution:
dotnet/runtime#35988

Steps to Reproduce

  1. Compile the EF Get Started project
  2. Deploy release version with Ad-Hoc provisioning to a physical device
  3. Launch app

Expected Behavior

App Launches

Actual Behavior

App crashes

Environment

Microsoft Visual Studio Enterprise 2019
Version 16.7.3
VisualStudio.16.Release/16.7.3+30503.244
Microsoft .NET Framework
Version 4.8.03752

Installed Version: Enterprise

VisualStudio.Mac 1.0
Mac Extension for Visual Studio

Xamarin 16.7.000.440 (d16-7@358f3c6)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer 16.7.0.495 (remotes/origin/d16-7@79c0c522c)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates 16.7.85 (1bcbbdf)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK 11.0.2.0 (d16-7/025fde9)
Xamarin.Android Reference Assemblies and MSBuild support.
Mono: 83105ba
Java.Interop: xamarin/java.interop/d16-7@1f3388a
ProGuard: Guardsquare/proguard@ebe9000
SQLite: xamarin/sqlite@1a3276b
Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-7@017078f

Xamarin.iOS and Xamarin.Mac SDK 13.20.2.2 (817b6f7)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

Build Logs

https://gist.github.com/rlasker-b2w/eb8cdd49435354e50369b74e116f13fc

Example Project (If Possible)

N/A

@rolfbjarne
Copy link
Member

I can reproduce, the Release configuration works if the linker is turned off (set "Linker behavior" to "Don't Link" in the iOS project's iOS Build options page).

The problem is that EntityFramework isn't linker-safe, this is what happens with the linker enabled:

System.TypeInitializationException: The type initializer for 'Microsoft.EntityFrameworkCore.Query.QueryableMethods' threw an exception. ---> System.InvalidOperationException: Sequence contains no matching element
  at System.Linq.Enumerable.Single[TSource] (System.Collections.Generic.IEnumerable`1[T] source, System.Func`2[T,TResult] predicate) [0x0006b] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/System.Linq/src/System/Linq/Single.cs:80 
  at Microsoft.EntityFrameworkCore.Query.QueryableMethods..cctor () [0x0001c] in <3680be5f188747439788d707f1cb36b7>:0 

This is already reported and known: dotnet/efcore#10963, so I'm going to close this.

@rolfbjarne rolfbjarne added this to the Future milestone Sep 23, 2020
@rolfbjarne rolfbjarne added iOS Issues affecting iOS support The issue is related to support labels Sep 23, 2020
@rlasker-trimble
Copy link
Author

@rolfbjarne is it possible that we are looking at two separate issues? The NotSupportedPlatform exception is quite specifically called out as being an issue with Xamarin.iOS using a version of microsoft.extensions.dependencyinjection that sets the IL_EMIT variable and it not being supported in ios. Read here.

@rolfbjarne
Copy link
Member

@rlasker-b2w can you still reproduce the PlatformNotSupportedException if you disable the linker in your Release build?

@rlasker-trimble
Copy link
Author

@rolfbjarne so far it does not appear to be logging the platform not supported exception after disabling the linker and functionality seems to be working as expected. Thanks for your help in this manner. I'm curious if there is any guidance on creating a linker file for Microsoft Extensions? Disabling the linker has it's own issues.

@rolfbjarne
Copy link
Member

I'm curious if there is any guidance on creating a linker file for Microsoft Extensions? Disabling the linker has it's own issues.

We have this: https://docs.microsoft.com/en-us/xamarin/ios/deploy-test/linker?tabs=macos#controlling-the-linker, but nothing specific for Microsoft.Extensions.

@rlasker-trimble
Copy link
Author

@rolfbjarne Thanks for the link. It should also be noted that Microsoft documentation says to submit a bug to this repository if your application requires "Don't Link" in order to run:

If your application only works with -nolink, please submit a bug report.

I noticed that this item was added to "Future" milestone. Since this item is closed will this be updated to track any progress?

@rolfbjarne
Copy link
Member

@rolfbjarne Thanks for the link. It should also be noted that Microsoft documentation says to submit a bug to this repository if your application requires "Don't Link" in order to run:

If your application only works with -nolink, please submit a bug report.

Yes, that's correct, but that doesn't necessarily mean that the bug is in the code in this repository. The diagnosis I did showed that the bug is in the Entity.Framework code, and I found an issue already open in that repository, which means this bug can be closed (and discussion should continue in the EF issue).

I noticed that this item was added to "Future" milestone. Since this item is closed will this be updated to track any progress?

No, subscribe to the EF issue (dotnet/efcore#10963) to get updates.

@ghost ghost locked as resolved and limited conversation to collaborators Apr 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
iOS Issues affecting iOS support The issue is related to support
Projects
None yet
Development

No branches or pull requests

2 participants