Megabit / Blazorise

Blazorise is a component library built on top of Blazor with support for CSS frameworks like Bootstrap, Tailwind, Bulma, AntDesign, and Material.
https://blazorise.com/
Other
3.26k stars 526 forks source link

Bar component doesn't work with Maui Blazor on iPhone in release configuration when setting Mode component parameter #4166

Open emanuelpaul opened 1 year ago

emanuelpaul commented 1 year ago

Describe the bug Bar component doesn't work on dotnet maui blazor on iPhones in release configuration when using Mode compoenent parameter, but it works on iOS simulators and on iPhones using Debug configuration. Tested on

It works fine on simulators:

It doesn't work on real iphone devices. I tested on:

Exception that occurs:

Unable to set property 'Mode' on object of type 'Blazorise.Bar'. The error was: Attempting to JIT compile method '(wrapper delegate-invoke) void <Module>:invoke_callvirt_void_Bar_BarMode (Blazorise.Bar,Blazorise.BarMode)' while running in aot-only mode. See https://docs.microsoft.com/xamarin/ios/internals/limitations for more information.

To Reproduce Steps to reproduce the behavior: Steps to reproduce the behavior:

Expected behavior Bar shouldn't trigger an exception when setting the Mode parameter.

Screenshots image

Additional context Exception details: Unable to set property 'Mode' on object of type 'Blazorise.Bar'. The error was: Attempting to JIT compile method '(wrapper delegate-invoke) void :invoke_callvirt_void_Bar_BarMode (Blazorise.Bar,Blazorise.BarMode)' while running in aot-only mode. See https://docs.microsoft.com/xamarin/ios/internals/limitations for more information.

at Microsoft.AspNetCore.Components.Reflection.ComponentProperties.g__SetProperty|3_0(Object , PropertySetter , String , Object ) at Microsoft.AspNetCore.Components.Reflection.ComponentProperties.SetProperties(ParameterView& , Object ) at Microsoft.AspNetCore.Components.ComponentBase.SetParametersAsync(ParameterView parameters) at Blazorise.BaseComponent.SetParametersAsync(ParameterView parameters) at Microsoft.AspNetCore.Components.Rendering.ComponentState.SupplyCombinedParameters(ParameterView )

Is there any workaround for setting Mode=BarMode.VerticalInline and Visible=false ? Maybe using attributes ?

David-Moreira commented 1 year ago

This error is quite strange... as it seems its the Blazor framework itself that has no access to these Parameters... kinda like if they were trimmed... (We had a similar problem recently)

I can notice that both properties you're mentioning happen to be virtual. Now I'm pretty sure a whole lot more should be breaking as there's nothing special about Mode in relation to other existing Parameter and other enums except that this one is Virtual. image image

@stsrki maybe we can try a different approach other then virtual? An internal getter/setter that we override ourselves? Oh and as a reminder they're virtual because of a specific override for AntDesignit seems. image

Could we do a test run with a test release with @emanuelpaul where we make these regular instead?

And any of you think we should report this somewhere? I'm not even sure where... Xamarin.iOS?

Another thing, if you would be some kind @emanuelpaul If you had the time, you could test making a TestComponent with virtual Parameters, see if it also breaks?

stsrki commented 1 year ago

A long time ago, sometime in 2019, I reported an issue to the .NET team regarding the virtual parameter properties. If I remember correctly, the problem should be long fixed by now. Maybe something is different for MAUI runtimes.

@David-Moreira We could try to add an internal, eg. virtual bool VisibleInternal that would be used instead. It's an option. But I would rather not if possible.

David-Moreira commented 1 year ago

Alright, Let's wait and see if @emanuelpaul can do us the favor of testing virtual on his end.

emanuelpaul commented 1 year ago

Because on ios native AOT is required, when publishing in release mode a maui project trimming is used. This cannot be turned off for release builds in maui for ios at least.

image

Trimming has limitations especially when reflection is used. This might cause the issue.

There are several was mitigate this problem described here

Sorry for late response.

David-Moreira commented 1 year ago

Because on ios native AOT is required, when publishing in release mode a maui project trimming is used. This cannot be turned off for release builds in maui for ios at least.

image

Trimming has limitations especially when reflection is used. This might cause the issue.

There are several was mitigate this problem described here

Sorry for late response.

Right we know as much... But we are not using reflection ourselves. Blazor might use it to set parameters but there might be something specific to virtual that we are missing.

Can you run the test we ask on your ios, pls?

emanuelpaul commented 1 year ago

Is there a package preview version that I can use ?

David-Moreira commented 1 year ago

@emanuelpaul I mean this: image

Since we suspect it might just be virtual Parameters that are being trimmed or there's something off about them.

emanuelpaul commented 1 year ago

Just did the test. I updated the counter component to use a virtual parameter and used it. The same error seems to occur. Source code

Unable to set property 'StartCount' on object of type 'BlazoriseMaui.Pages.Counter'. The error was: Attempting to JIT compile method '(wrapper delegate-invoke) void <Module>:invoke_callvirt_void_Counter_int (BlazoriseMaui.Pages.Counter,int)' 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 , PropertySetter , String , Object )
   at Microsoft.AspNetCore.Components.Reflection.ComponentProperties.SetProperties(ParameterView& , Object )
   at Microsoft.AspNetCore.Components.ComponentBase.SetParametersAsync(ParameterView parameters)
   at Microsoft.AspNetCore.Components.Rendering.ComponentState.SupplyCombinedParameters(ParameterView )
David-Moreira commented 1 year ago

Right and maybe it should work. We should report this. Would you like to report @emanuelpaul ? Maybe you can do it over here : https://github.com/dotnet/aspnetcore/issues and then they redirect if its in the wrong repo.

Can you try this as a workaround on your Counter? This might be enough to circumvent the problem.

        public override Task SetParametersAsync( ParameterView parameters )
        {
            foreach ( var parameter in parameters )
            {
                switch ( parameter.Name )
                {
                    case nameof( StartCount ):
                        StartCount = (int)parameter.Value;
                        break;
                    default:
                        throw new ArgumentException( $"Unknown parameter: {parameter.Name}" );
                }
            }

            return base.SetParametersAsync( ParameterView.Empty );
        }
github-actions[bot] commented 1 year ago

This is an automated message reminding that this issue is expecting the author's answer.

David-Moreira commented 1 year ago

https://github.com/dotnet/runtime/issues/78712

David-Moreira commented 1 year ago

Reminder to retest with dotnet 8 preview as requested by dotnet team.

David-Moreira commented 1 year ago

Hello @emanuelpaul can you retry this with dotnet 8? We've released v1.3 with dotnet 8 support (preview). The dotnet team asked if we could test this.

emanuelpaul commented 1 year ago

Hello @emanuelpaul can you retry this with dotnet 8? We've released v1.3 with dotnet 8 support (preview). The dotnet team asked if we could test this.

I'll try to do it this weekend

David-Moreira commented 1 year ago

Hello @emanuelpaul can you retry this with dotnet 8? We've released v1.3 with dotnet 8 support (preview). The dotnet team asked if we could test this.

I'll try to do it this weekend

Appreciated.

David-Moreira commented 1 year ago

Hello @emanuelpaul Sorry to keep bothering you with this. :) Friendly reminder, If you could please do us the favor of testing this, it would very much be appreciated.

emanuelpaul commented 1 year ago

Hello, sorry for late response. It doesn't seems to work and now I'm unable to see the error using safari dev tools.

I used sdk 8.0.100-preview.7.23376.3. Code is on branch bar-bug-net8

David-Moreira commented 1 year ago

Hello @emanuelpaul Thanks for the help. Just to be sure, this is tested with a real IPhone device as you've told us in the bug report?

image


This does not happen on the emulator. Right?

emanuelpaul commented 1 year ago

It doesn't ssems to work on simulator or on the iphone. I created another branch button-bug-net8-android where I just added a button to see if it works. I tested it using an android emulator.
It doesn't work. I just upgraded the .net version to 8 and updated the packages to the latest version, Maybe I need to do something else I haven't had the time use use .net 8 preview until now. When I click on the button I can see the following error is generated:


[chromium] [INFO:CONSOLE(1)] "Uncaught Error: No interop methods are registered for renderer 0", source: https://0.0.0.0/_framework/blazor.webview.js (1)```
David-Moreira commented 1 year ago

It doesn't ssems to work on simulator or on the iphone. I created another branch button-bug-net8-android where I just added a button to see if it works. I tested it using an android emulator. It doesn't work. I just upgraded the .net version to 8 and updated the packages to the latest version, Maybe I need to do something else I haven't had the time use use .net 8 preview until now. When I click on the button I can see the following error is generated:

[chromium] [INFO:CONSOLE(1)] "Uncaught Error: No interop methods are registered for renderer 0", source: https://0.0.0.0/_framework/blazor.webview.js (1)```

That does not seem like the same error though

emanuelpaul commented 1 year ago

It doesn't ssems to work on simulator or on the iphone. I created another branch button-bug-net8-android where I just added a button to see if it works. I tested it using an android emulator. It doesn't work. I just upgraded the .net version to 8 and updated the packages to the latest version, Maybe I need to do something else I haven't had the time use use .net 8 preview until now. When I click on the button I can see the following error is generated:

[chromium] [INFO:CONSOLE(1)] "Uncaught Error: No interop methods are registered for renderer 0", source: https://0.0.0.0/_framework/blazor.webview.js (1)```

That does not seem like the same error though

yeah it might be something related to .net 8. The code from the android branch can be tested easier, the only thing needed is visual studio with the maui workload.

stsrki commented 1 month ago

What is the status of this error? Is it safe to close the ticket?

David-Moreira commented 1 month ago

I have no idea, since we are not capable of testing under the same conditions. @emanuelpaul do you still find difficulties with this?

If I may give some guidance, since Trimming / AOT isn't always 100% compatible, you could try disabling these features when compiling for release: Here's a snippet for Android release, modify it accordingly for iOS

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net8.0-android|AnyCPU'">
    <AndroidPackageFormat>apk</AndroidPackageFormat>
    <RunAOTCompilation>false</RunAOTCompilation>
    <EnableLLVM>false</EnableLLVM>
    <PublishTrimmed>false</PublishTrimmed>
</PropertyGroup>