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

iOS Blazor app crashes with TargetPlatformVersion=15.4 #10958

Closed
rolfbjarne opened this issue Oct 27, 2022 · 8 comments
Closed

iOS Blazor app crashes with TargetPlatformVersion=15.4 #10958

rolfbjarne opened this issue Oct 27, 2022 · 8 comments
Labels
area-blazor Blazor Hybrid / Desktop, BlazorWebView investigate platform/iOS 🍎 s/duplicate 2️⃣ This issue or pull request already exists s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working

Comments

@rolfbjarne
Copy link
Member

Description

Exception at startup:

Test[28391:669570] Microsoft.iOS: Received unhandled ObjectiveC exception: System.TypeLoadException Could not set up parent class, due to: Invalid generic instantiation assembly:/Users/rolf/Library/Developer/CoreSimulator/Devices/193C9988-DAF1-41DC-A1AC-1ED09D92A85B/data/Containers/Bundle/Application/0FE572FB-C804-4EC6-9C6A-A9C1754A763F/Test.app/Microsoft.Maui.dll type:ViewHandler`2 member:(null) (System.TypeLoadException)
   at System.RuntimeType.GetConstructors_internal(BindingFlags bindingAttr, RuntimeType reflectedType)
   at System.RuntimeType.GetConstructorCandidates(String name, BindingFlags bindingAttr, CallingConventions callConv, Type[] types, Boolean allowPrefixLookup)
   at System.RuntimeType.GetDefaultConstructor()
   at System.RuntimeType.CreateInstanceMono(Boolean nonPublic, Boolean wrapExceptions)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic, Boolean wrapExceptions)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at System.Activator.CreateInstance(Type type)
   at Microsoft.Maui.Hosting.Internal.MauiFactory.CreateInstance(ServiceDescriptor item)
   at Microsoft.Maui.Hosting.Internal.MauiFactory.GetService(ServiceDescriptor descriptor)
   at Microsoft.Maui.Hosting.Internal.MauiFactory.GetService(Type serviceType, ServiceDescriptor single, IEnumerable`1 enumerable)
   at Microsoft.Maui.Hosting.Internal.MauiFactory.GetService(Type serviceType)
   at Microsoft.Maui.Hosting.Internal.MauiHandlersFactory.GetHandler(Type type)
   at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context)
   at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement view, IMauiContext context)
   at Microsoft.Maui.Handlers.ContentViewHandler.UpdateContent(IContentViewHandler handler)
   at Microsoft.Maui.Handlers.ContentViewHandler.MapContent(IContentViewHandler handler, IContentView page)
   at Microsoft.Maui.PropertyMapper`2.<>c__DisplayClass5_0[[Microsoft.Maui.IContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Handlers.IContentViewHandler, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].<Add>b__0(IElementHandler h, IElement v)
   at Microsoft.Maui.PropertyMapper.UpdatePropertyCore(String key, IElementHandler viewHandler, IElement virtualView)
   at Microsoft.Maui.PropertyMapper.UpdateProperties(IElementHandler viewHandler, IElement virtualView)
   at Microsoft.Maui.Handlers.ElementHandler.SetVirtualView(IElement view)
   at Microsoft.Maui.Handlers.ViewHandler`2[[Microsoft.Maui.IContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.ContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IView view)
   at Microsoft.Maui.Handlers.ContentViewHandler.SetVirtualView(IView view)
   at Microsoft.Maui.Handlers.ViewHandler`2[[Microsoft.Maui.IContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.ContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IElement view)
   at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler newHandler)
   at Microsoft.Maui.Controls.Element.set_Handler(IElementHandler value)
   at Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler(IElementHandler value)
   at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context)
   at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement view, IMauiContext context)
   at Microsoft.Maui.Platform.ElementExtensions.ToUIViewController(IElement view, IMauiContext context)
   at Microsoft.Maui.Handlers.WindowHandler.MapContent(IWindowHandler handler, IWindow window)
   at Microsoft.Maui.PropertyMapper`2.<>c__DisplayClass5_0[[Microsoft.Maui.IWindow, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Handlers.IWindowHandler, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].<Add>b__0(IElementHandler h, IElement v)
   at Microsoft.Maui.PropertyMapper.UpdatePropertyCore(String key, IElementHandler viewHandler, IElement virtualView)
   at Microsoft.Maui.PropertyMapper.UpdateProperties(IElementHandler viewHandler, IElement virtualView)
   at Microsoft.Maui.Handlers.ElementHandler.SetVirtualView(IElement view)
   at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler newHandler)
   at Microsoft.Maui.Controls.Element.set_Handler(IElementHandler value)
   at Microsoft.Maui.Platform.ElementExtensions.SetHandler(INativeObject nativeElement, IElement element, IMauiContext context)
   at Microsoft.Maui.Platform.ElementExtensions.SetWindowHandler(UIWindow platformWindow, IWindow window, IMauiContext context)
   at Microsoft.Maui.Platform.ApplicationExtensions.CreatePlatformWindow(IApplication application, UIWindowScene windowScene, NSDictionary[] states)
   at Microsoft.Maui.Platform.ApplicationExtensions.CreatePlatformWindow(IUIApplicationDelegate platformApplication, IApplication application, UIApplication uiApplication, NSDictionary launchOptions)
   at Microsoft.Maui.MauiUIApplicationDelegate.FinishedLaunching(UIApplication application, NSDictionary launchOptions)

Steps to Reproduce

Test project: Test-8a5a3f4.zip

  1. Open test project.
  2. Launch in simulator.

Alternatively:

  1. dotnet new maui-blazor
  2. Modify the csproj to set TargetPlatformVersion to 15.4

Binlog:
msbuild.binlog.zip

The underlying reason for the crash is that a different Microsoft.AspNetCore.Components.WebView.Maui.dll assembly is picked by the build.

In the crashing version, this version is used:

~/.nuget/packages/microsoft.aspnetcore.components.webview.maui/6.0.541/lib/net6.0/Microsoft.AspNetCore.Components.WebView.Maui.dll

While the working assembly comes from:

~/.nuget/packages/microsoft.aspnetcore.components.webview.maui/6.0.541/lib/net6.0-ios16.0/Microsoft.AspNetCore.Components.WebView.Maui.dll

Note that the target framework is different in the path: net6.0 vs net6.0-ios16.0 – the crashing app is picking up the general .NET 6 version of this assembly, and not the one with iOS-specific code.

This is because of the TargetPlatformVersion property in the project file: if this is set to lower than 16.0, the general .NET 6 version of the assembly is picked, but if it’s 16.0 (or higher), then the net6.0-ios16.0 version is picked. As far as I can tell this is working as expected (if you’re building with the iOS 15.4 API for instance, you can’t expect to consume an assembly that potentially uses iOS 16.0 API).

Another point of interest is that the 6.0.540 version of this NuGet has a net6.0-ios15.4 assembly, which would presumably work fine: https://nuget.info/packages/Microsoft.AspNetCore.Components.WebView.Maui/6.0.540

So I'm not sure where the bug is, but in any case the crash a terrible way to report this problem. It took me quite a few hours to track it down, and I wouldn't expect customers to be able to without even more time wasted.

Link to public reproduction project repository

See zip above

Version with bug

7.0 Release Candidate 2

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

iOS 16

Did you find any workaround?

Set TargetPlatformVersion to 16.0:

<TargetPlatformVersion>16.0</TargetPlatformVersion>

Relevant log output

$ dotnet workload list

Installed Workload Id      Manifest Version                         Installation Source
---------------------------------------------------------------------------------------
macos                      12.3.1186-rc.2/7.0.100-rc.2              SDK 7.0.100-rc.2
maui-android               7.0.0-rc.2.6866/7.0.100-rc.2             SDK 7.0.100-rc.2
ios                        16.0.1271-rc.2-xcode14/7.0.100-rc.2      SDK 7.0.100-rc.2
maccatalyst                15.4.1186-rc.2/7.0.100-rc.2              SDK 7.0.100-rc.2
android                    33.0.0-rc.2.202/7.0.100-rc.2             SDK 7.0.100-rc.2
@rolfbjarne rolfbjarne added the t/bug Something isn't working label Oct 27, 2022
@Eilon Eilon added the area-blazor Blazor Hybrid / Desktop, BlazorWebView label Oct 27, 2022
@mkArtakMSFT mkArtakMSFT removed the area-blazor Blazor Hybrid / Desktop, BlazorWebView label Oct 31, 2022
@mkArtakMSFT
Copy link
Member

@rolfbjarne from the details provided here it doesn't seem to be Blazor specific. Did you actually confirm that or should someone from the MAUI look into this instead?

@rolfbjarne
Copy link
Member Author

@mkArtakMSFT I first tried to reproduce with a plain MAUI app (no Blazor), and wasn't able to (but maybe I just didn't try hard enough). I guess whomever is responsible for the Microsoft.AspNetCore.Components.WebView.Maui assembly should look at it?

@hartez hartez added Blazor ❤️ MAUI Issues in MAUI functionality that affect Blazor, but are not bugs in Blazor itself and removed Blazor ❤️ MAUI Issues in MAUI functionality that affect Blazor, but are not bugs in Blazor itself labels Nov 1, 2022
@jfversluis jfversluis added the area-blazor Blazor Hybrid / Desktop, BlazorWebView label Nov 4, 2022
@TanayParikh
Copy link
Contributor

Given the call stack is entirely .NET MAUI, could you please clarify why you believe the Microsoft.AspNetCore.Components.WebView.Maui assembly is the culprit here?

@rolfbjarne
Copy link
Member Author

@TanayParikh I created created two apps, one that worked and one that didn't. Then I copied the Microsoft.AspNetCore.Components.WebView.Maui.dll between them, and if I copied the version from the failing app to the working app, the working app started failing, and when I did the reverse, the failing app started working.

@mkArtakMSFT mkArtakMSFT added investigate and removed t/bug Something isn't working labels Nov 8, 2022
@samhouts samhouts added the t/bug Something isn't working label Jul 31, 2023
@jinxinjuan jinxinjuan added s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage labels Aug 9, 2023
@jinxinjuan
Copy link

Verified this issue with Visual Studio Enterprise 17.6.2 build (405), Can repro on iOS platform with sample project. Test-8a5a3f4.zip

@mkArtakMSFT
Copy link
Member

@rolfbjarne is there a real-world scenario that you can think of which will lead customers to hitting this? In the last 2 years we've seen no customers complaining about this. So it's not clear if we should actually spend time on it.

@rolfbjarne
Copy link
Member Author

@mkArtakMSFT this was originally reported by an (internal) customer.

Looking at the most recent NuGet, I see that the problem can still occur:

https://nuget.info/packages/Microsoft.AspNetCore.Components.WebView.Maui/8.0.14

now if the customer sets TargetPlatformVersion=17.0 in their csproj, they'll get the generic net8.0 version of the assembly instead of the net8.0-ios17.2 version.

The good news is that we're working on making this easy to fix, once dotnet/sdk#30103 is fixed and published, the fix should be as easy as adjusting the TargetFramework in the corresponding csproj from TargetFramework=net8.0-ios to TargetFramework=net8.0-ios17.0.

@mkArtakMSFT
Copy link
Member

Great, thanks @rolfbjarne.
Closing this then, as there is no change to be made in the framework, other than the SDK one that you linked.

@mkArtakMSFT mkArtakMSFT closed this as not planned Won't fix, can't repro, duplicate, stale Apr 19, 2024
@mkArtakMSFT mkArtakMSFT added the s/duplicate 2️⃣ This issue or pull request already exists label Apr 19, 2024
@github-actions github-actions bot locked and limited conversation to collaborators May 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Blazor Hybrid / Desktop, BlazorWebView investigate platform/iOS 🍎 s/duplicate 2️⃣ This issue or pull request already exists s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

10 participants