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.27k stars 531 forks source link

`<Select>` doesn't work in an AOT Release version of a MAUI Blazor MacCatalyst app for macOS #4420

Open Jinjinov opened 1 year ago

Jinjinov commented 1 year ago

Describe the bug

This is not exactly a Blazorise bug, but I don't know who to ask for help. You can delete this issue if it doesn't belong here.

Blazorise works great in Blazor WASM, with Photino on Linux, with Maui on Windows and Android and iOS.

On macOS it works great with Maui in Debug, but in Release (published with AOT) it throws this exception:

Unable to set property 'Value' on object of type 'Blazorise.SelectItem`1[[Ididit.Backup.DataFormat, Ididit, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]'. 
The error was: 
Attempting to JIT compile method '(wrapper delegate-invoke) void <Module>:invoke_callvirt_void_SelectItem`1<DataFormat>_DataFormat (Blazorise.SelectItem`1<Ididit.Backup.DataFormat>,Ididit.Backup.DataFormat)' 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.ParameterView.SetParameterProperties(Object )
   at Microsoft.AspNetCore.Components.ComponentBase.SetParametersAsync(ParameterView parameters)
   at Blazorise.BaseComponent.SetParametersAsync(ParameterView parameters)
   at Microsoft.AspNetCore.Components.Rendering.ComponentState.SupplyCombinedParameters(ParameterView )

Do you have any idea what the problem could be?

Is there anything I could do to fix this?

To Reproduce Steps to reproduce the behavior:

  1. create a Maui Blazor project
  2. include Blazorise
  3. use a <Select> control
  4. run the app
stsrki commented 1 year ago

I can only assume that AOT is somehow stripping or changing the Value on SelectItem. It's just a guess. Since we don't have a mac to test the code it would be hard to confirm.

Jinjinov commented 1 year ago

I replaced <Select> and <SelectItem> with <select> and <option> and now it works.

In <select> I used value instead of SelectedValue and @onchange instead of SelectedValueChanged

In <option> I used value instead of Value

Everything else is the same.

I am trying to understand the error:

Attempting to JIT compile method 
'(wrapper delegate-invoke) void <Module>:invoke_callvirt_void_SelectItem`1<DataFormat>_DataFormat (Blazorise.SelectItem`1<Ididit.Backup.DataFormat>,Ididit.Backup.DataFormat)' 
while running in aot-only mode.

So, there is:

Why would native html controls work?

Do they use a method with an object parameter instead of a generic parameter?

Looking at the Blazorise code, this seems like one possibility for this error:

public partial class SelectItem<TValue> : BaseComponent, ISelectItem<TValue>, IDisposable

The constructor with a generic parameter is one obvious difference between <Select> / <SelectItem> and <select> / <option>

stsrki commented 1 year ago

Do you have TValue defined on both Select and SelectItem?

Jinjinov commented 1 year ago

No, only on <Select>

stsrki commented 1 year ago

Can you try matching TValue on both?

Jinjinov commented 1 year ago

I tried matching TValue on both, but I still got the same exception.

David-Moreira commented 1 year ago

Not easy to tell from that stack trace but we have a similar issue open. Where a release built application trimming is having a similar behaviour because of a virtual Parameter. This might be the same, there's this one : [CascadingParameter] protected virtual Select ParentSelect { get; set; }