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] Trimming / AOT issue after publish in .NET MAUI Blazor app #14271

Closed
ScarletKuro opened this issue Mar 29, 2023 · 12 comments
Closed

[iOS] Trimming / AOT issue after publish in .NET MAUI Blazor app #14271

ScarletKuro opened this issue Mar 29, 2023 · 12 comments
Labels
area-blazor Blazor Hybrid / Desktop, BlazorWebView external platform/iOS 🍎 t/bug Something isn't working

Comments

@ScarletKuro
Copy link

ScarletKuro commented Mar 29, 2023

Description

I'm not sure if this issue should go here or under the dotnet/runtime, but the problem is following.
MudBlazor users report problem when they publish app on iOS. Meanwhile, it runs normally in Debug / Release mode on the device.
The problem is shown in the stack trace. I suspect that the setter property is getting removed and then SetParametersAsync -> ComponentProperties.SetProperties throws exception, because it's using reflection to set the value.
At first I thought it's some MudBlazor trimming issue, but it's not. The razor components are protected via Blazor framework, the RenderTreeBuilder, RootComponentMappingCollection etc are annotated with [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] and it should preserve everything in the component.
Worth to mention that MudBlazor supports trimming in general, and it's used by many people and there was never such problem encountered.
The same code will work perfectly fine when used in Browser and published with trimming enabled!

If I'm not wrong, iOS has AOT compilation requirements, and maybe it's way too aggressive. I should note that Blazor supports only partial TrimMode, but I'm not sure if MAUI uses ILLink as Blazor WASM does.

Additional information: Android is unaffected. Internal MudBlazor issue: MudBlazor/MudBlazor#6310

Steps to Reproduce

  1. Clone reproduction link
  2. Publish iOS and sign Ad Hoc / App Store
  3. Install app
  4. Launch

Link to public reproduction project repository

https://github.com/QwertyMC/MauiBlazorTest

Version with bug

7.0 (current)

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

iOS 14 and higher

Did you find any workaround?

No. Seems ILLink.Descriptors.xml / BlazorLinkerDescriptor doesn't have any effect.

Relevant log output

Unable to set property 'Required' on object of type 'MudBlazor.MudTextField`1[[System.String, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]'. 
The error was: Attempting to JIT compile method '(wrapper delegate-invoke) void <Module>:invoke_callvirt_void_MudTextField`1<string>_bool (MudBlazor.MudTextField`1<string>,bool)' while running in aot-only mode. 
See https://docs.microsoft.com/xamarin/ios/internals/limitations for more information.
:    at Microsoft.AspNetCore.Components.Reflection.ComponentProperties.<SetProperties>g__SetProperty|3_0(Object target, PropertySetter writer, String parameterName, Object value)
   at Microsoft.AspNetCore.Components.Reflection.ComponentProperties.SetProperties(ParameterView& parameters, Object target)
   at Microsoft.AspNetCore.Components.ComponentBase.SetParametersAsync(ParameterView parameters)
   at MudBlazor.MudBaseInput`1[[System.String, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].<>n__1(ParameterView parameters)
   at MudBlazor.MudBaseInput`1.<SetParametersAsync>d__177[[System.String, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
@ScarletKuro ScarletKuro added the t/bug Something isn't working label Mar 29, 2023
@Eilon Eilon added the area-blazor Blazor Hybrid / Desktop, BlazorWebView label Mar 29, 2023
@Eilon
Copy link
Member

Eilon commented Mar 29, 2023

Blazor folks - I think we've seen similar issues when using MudBlazor before. Does this look familiar and/or related to past issues?

@ScarletKuro
Copy link
Author

ScarletKuro commented Mar 29, 2023

I think we've seen similar issues when using MudBlazor before. Does this look familiar and/or related to past issues?

Doesn't look familiar. All previous issues were easy to trace and fix. It was mainly related to JS Interop.
In this case Required is just a bool property. There is no reflection from our side, only the ones that are happening inside Blazor. There shouldn't be done anything special from MudBlazor in order for this property to be preserved since all the job is already done by the Blazor: here and here, the Index.razorthat contains the MudBlazor component is rendering it through RenderTreeBuilder that guarantees that everything inside the component is preserved.

@ScarletKuro
Copy link
Author

Sorry to tag directly, but can you assist @vitek-karas

@ScarletKuro ScarletKuro changed the title [iOS] Trimming issue after publish [iOS] Trimming issue after publish in .NET MAUI Blazor app Mar 29, 2023
@vitek-karas
Copy link
Member

I think we will need somebody from the iOS AOT side:
@ivanpovazan - would you know? Or add somebody who might?

The question for me is "What does that failure actually mean?"

  • Does it mean the setter method is simply not there at all (trimming issue)
  • The setter property exists in IL, but it's not AOTed and thus it fails on pure-AOT mode since it can't JIT it on demand (AOT compiler problem? Or maybe it should run the interpreter but for some reason it can't)
  • Something else going on - like the setter method is AOTed, but there's no metadata around it, so it's not invokable through reflection for example (this would probably be AOT compiler problem - maybe ILStrip being too aggressive?)

I don't know how to answer this, since I know very little about mono iOS AOT.

What are the versions in use - the SDK version and TFM of the app?

@ScarletKuro
Copy link
Author

What are the versions in use - the SDK version and TFM of the app?

As I understand TFM is net7.0-ios, sdk 7.0.104-7.0.202
Is this correct @assemblysoft?
Just in case, they have the same issue and they are ready to provide any assist:

We are able to run the application on a physical iPhone (iOS) by distributing directly from Visual Studio (without the need for a MAC in between) and it works fine. As soon as we publish to the App Store or Testflight, although Apple is happy with the distribution, it fails as above. We have added remote logging, so we can capture the stack trace and happy to assist you with any additional info you might need. We are available anytime, if required to jump on a call or can share access to our app distribution in Testflight, if that helps.

@ScarletKuro
Copy link
Author

ScarletKuro commented Mar 29, 2023

Maybe worth to mention that
MudTextField is a generic MudTextField<T> that inherits from MudDebouncedInput<T> -> MudBaseInput<T> -> MudFormComponent<T, string> -> MudComponentBase -> ComponentBase.

The Required property is located in MudFormComponent<T, string>.

Could it hit the Limited Generics Support in iOS AOT?

@assemblysoft
Copy link

assemblysoft commented Mar 29, 2023

@ScarletKuro
net7.0-ios (14.0) 7.0.59/7.0.100
(VS 17.5.33516.290)

@ScarletKuro
Copy link
Author

ScarletKuro commented Mar 29, 2023

Maybe @rolfbjarne could assist as well.

Currently I would suggest @assemblysoft to try setting

<!-- Or None -->
<MtouchLink>SdkOnly</MtouchLink>
<UseInterpreter>True</UseInterpreter> 

in the PropertyGroup.
As I understand, there is discussion to make this default on iOS #13019.

@ScarletKuro ScarletKuro changed the title [iOS] Trimming issue after publish in .NET MAUI Blazor app [iOS] Trimming / AOT issue after publish in .NET MAUI Blazor app Mar 29, 2023
@rolfbjarne
Copy link
Member

This part of the error:

The error was: Attempting to JIT compile method '(wrapper delegate-invoke) void :invoke_callvirt_void_MudTextField1<string>_bool (MudBlazor.MudTextField1,bool)' while running in aot-only mode.

Indicates that the AOT compiler ran into a method it couldn't AOT-compile, and then executing that method failed at runtime.

It's likely that enabling the interpreter will fix this (as @ScarletKuro) suggested.

@assemblysoft
Copy link

assemblysoft commented Mar 30, 2023

@ScarletKuro @rolfbjarne can confirm that after applying the above, this has resolved the issue and we have successfully deployed and tested via App Store Connect (TestFlight).
Many Thanks both!

@ivanpovazan
Copy link
Member

This seems to be a duplicate of: #13279 and further: dotnet/runtime#78889

There is a global tracking issue: dotnet/runtime#83329 which would hopefully resolve all related issues.

@ScarletKuro
Copy link
Author

ScarletKuro commented Mar 30, 2023

Thanks everyone for such fast help.
Ok, I will close the issue since apparently there are multiple issues created, but what I would like to happen is:

  • The documentation gets improved and added to learn.microsoft. The UseInterpreter is a hard discoverable option. I found it in EF core issue, and I wasn't sure what it's doing from the name and if it's AOT related. It's also hard to find the drawbacks of using this option.
  • A better exception messages if applicable for this case.
  • Enabling interpreter by default when publishing on iOS since too many customers running into the problems rn.
  • Improve AOT in the future, so that it could AOT-compile such cases.

@ghost ghost locked as resolved and limited conversation to collaborators Apr 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Blazor Hybrid / Desktop, BlazorWebView external platform/iOS 🍎 t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants