Skip to content

[WASM] When AOT is used it throws Arg_InvalidCastException #100527

Closed

Description

@ScarletKuro

Description

Hello.

One of our users created this issue: MudBlazor/MudBlazor#8493

When MudBlazor is published using AOT it throws such error:

crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: Arg_InvalidCastException
System.InvalidCastException: Arg_InvalidCastException
   at MudBlazor.State.ParameterSet.SetParametersAsync(Func`2 , ParameterView )

After reviewing our code I haven't found anything suspicious and I believe this is AOT bug. The code is trivial and we are using Blazor API.
We are not doing any explicit cast, the only thing where cast is happening behind the roof is ParameterView.TryGetValue<T>(string, out T) which casts object to T but this is part of the Blazor API.
The code do work when you only enable trimming but AOT disabled, which makes me believe even more that it's AOT bug.

The code of the method: https://github.com/MudBlazor/MudBlazor/blob/9cd082755650afbce8356d6034de5a395e6e794e/src/MudBlazor/State/ParameterSet.cs#L71
And the code of the whole thing is located here: https://github.com/MudBlazor/MudBlazor/tree/9cd082755650afbce8356d6034de5a395e6e794e/src/MudBlazor/State
Below you can find a minimal reproduction in zip that contains empty BlazorApp that references MudBlazor.

Reproduction Steps

BlazorApp_AOT.zip

Publish with AOT enabled, run via IIS / IIS express and open the website in browser. You will immediately see exception.

Expected behavior

Not to throw exception and function as intended.

Actual behavior

Currently throws an exception when it shouldn't.
exception

Regression?

No response

Known Workarounds

No response

Configuration

.NET SDK:
Version: 8.0.202
Commit: 25674bb2f4
Workload version: 8.0.200-manifests.8cf8de6d

Runtime Environment:
OS Name: Windows
OS Version: 10.0.19045
OS Platform: Windows
RID: win-x64

Other information

No response

Activity

  1. added this to the 9.0.0 milestone on Apr 2, 2024
  2. added
    arch-wasmWebAssembly architecture
    untriagedNew issue has not been triaged by the area owner
    on Apr 2, 2024
  3. lambdageek commented on Apr 2, 2024

    @lambdageek
    Member

    Doesn't repro with 8.0.2 on a mac, serving with dotnet-serve, browsing with Chrome v123. Trying on Windows...

  4. ScarletKuro commented on Apr 2, 2024

    @ScarletKuro
    Author

    Here is the published files that were generated by the VS studio 2022 (17.9.4) "Publish"
    publish.zip

    that's how i run it:

    C:\Program Files (x86)\IIS Express>iisexpress /path:<path_here>\publish /port:9090 /clr:v2.0
    

    gif

  5. lambdageek commented on Apr 2, 2024

    @lambdageek
    Member

    Here is the published files that were generated by the VS studio 2022 (17.9.4) "Publish" publish.zip

    Thanks. Can repro using these published files.

    Also it repro'd building from source after I upgraded my SDK, runtime and workload to 8.0.3 / 8.0.203

    @lewing looks like a recent regression

  6. mgubis commented on Apr 22, 2024

    @mgubis

    Is there any news about the topic? I see current milestone 9.0.0 - this would render AOT not usable for us for quite some time ...

  7. lewing commented on Apr 22, 2024

    @lewing
    Member

    Here is the published files that were generated by the VS studio 2022 (17.9.4) "Publish" publish.zip

    Thanks. Can repro using these published files.

    Also it repro'd building from source after I upgraded my SDK, runtime and workload to 8.0.3 / 8.0.203

    @lewing looks like a recent regression

    8.0.2 -> 8.0.3 is roughtly 31691ff...13d578b correct?

  8. mgubis commented on Apr 22, 2024

    @mgubis

    Maybe this information helps: I tried to built with RuntimeFrameworkVersion = 8.0.2 with 8.0.4 SDK tools and it has resolved the problem:

    emcc "@C:\Users\magu\.nuget\packages\microsoft.netcore.app.runtime.mono.browser-wasm\8.0.2\runtimes\browser-wasm\native\src\emcc-default.rsp" -msimd128 "@C:\Users\magu\.nuget\packages\microsoft.netcore.app.runtime.mono.browser-wasm\8.0.2\runtimes\browser-wasm\native\src\emcc-link.rsp" "@C:\Work\WWImmoMA\trunk\WW.ImmoMA.Demo\Sources\WW.ImmoMA.Demo.Client\obj\Release\net8.0\wasm\for-publish\emcc-link.rsp"
     "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.3.1.34.Node.win-x64\8.0.4\tools\bin\node.exe" "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.3.1.34.Sdk.win-x64\8.0.4\tools\emscripten\src\compiler.js" C:\Users\magu\AppData\Local\Temp\2\tmp9ubi76vn.json --symbols-only
     "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.3.1.34.Sdk.win-x64\8.0.4\tools\bin\wasm-ld.exe" @C:\Users\magu\AppData\Local\Temp\2\emscripten_qz2s5pp5.rsp.utf-8
     "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.3.1.34.Node.win-x64\8.0.4\tools\bin\node.exe" "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.3.1.34.Sdk.win-x64\8.0.4\tools\emscripten\src\compiler.js" C:\Users\magu\AppData\Local\Temp\2\tmp8r1k8par.json
     "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.3.1.34.Sdk.win-x64\8.0.4\tools\bin\wasm-opt" --strip-dwarf --post-emscripten -O2 --low-memory-unused --zero-filled-memory --pass-arg=directize-initial-contents-immutable --strip-debug --strip-producers C:\Work\WWImmoMA\trunk\WW.ImmoMA.Demo\Sources\WW.ImmoMA.Demo.Client\obj\Release\net8.0\wasm\for-publish\dotnet.native.wasm -o C:\Work\WWImmoMA\trunk\WW.ImmoMA.Demo\Sources\WW.ImmoMA.Demo.Client\obj\Release\net8.0\wasm\for-publish\dotnet.native.wasm -g --mvp-features --enable-exception-handling --enable-mutable-globals --enable-sign-ext --enable-simd
     "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.3.1.34.Node.win-x64\8.0.4\tools\bin\node.exe" "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.3.1.34.Sdk.win-x64\8.0.4\tools\emscripten\tools\acorn-optimizer.js" C:\Users\magu\AppData\Local\Temp\2\emscripten_temp_vm096bc7\dotnet.native.js JSDCE minifyWhitespace --exportES6 -o C:\Users\magu\AppData\Local\Temp\2\emscripten_temp_vm096bc7\dotnet.native.jso1.js
    
  9. self-assigned this
    on Apr 23, 2024
  10. lambdageek commented on Apr 24, 2024

    @lambdageek
    Member

    This is a regression introduced by #97850 which made changes to the AOT runtime but did not make corresponding changes to the AOT comppiler. The compiler changes are in #101491 - for the 8.0 servicing. They are already in net9.0 main - in #94787

  11. e808080 commented on Jun 4, 2024

    @e808080

    Having the same issue with the latest .NET 8 SDK available for download (.NET 8.0.301). How did you solve this @mgubis ? Just set the RuntimeFrameworkVersion in the csproj? Is it safe to set that only for the Blazor Client project (and not Server project) or could there be mismatches then between server and client? We will have .NET 8.0.6 installed on the server.

  12. mgubis commented on Jun 4, 2024

    @mgubis

    @garcia252 - I have installed .NET 8.0.2 SDK to the development machine. I have changed both server and client to use new runtime:

    <RuntimeFrameworkVersion>8.0.2</RuntimeFrameworkVersion>

    I published project as self-contained and deployed to local server (not Azure) - so I was not able to check for any incompatibilities (although I think there should be none).

    Anyway, I believe, that it should be sufficient to switch RuntimeFrameworkVersion only for client project - published version of the WASM framework depends on the client project.

  13. ScarletKuro commented on Jun 7, 2024

    @ScarletKuro
    Author

    Having the same issue with the latest .NET 8 SDK available for download (.NET 8.0.301)

    Can confirm that the problem still exist in the latest SDK 8.0.301

  14. e808080 commented on Jun 12, 2024

    @e808080

    Verified that this issue still exists in the version released yesterday SDK 8.0.302 ...

  15. lambdageek commented on Jun 12, 2024

    @lambdageek
    Member

    Thanks, we'll take another look. /cc @steveisok

  16. lambdageek commented on Jun 17, 2024

    @lambdageek
    Member

    Looks like 8.0.6 / .NET SDK 8.0.302 didn't take any changes from after April 16th , #101491 was merged on April 30th. So the fix is not in yet.


    (I verified that 8.0.302 still repros the issue for me, while building a runtime and AOT compiler from the tip of https://github.com/dotnet/runtime/tree/release/8.0 apparently fixes it.)

  17. boukenka commented on Jul 4, 2024

    @boukenka

    @lambdageek When will it be fixed? I'm guessing it won't be in version 8.0.302 according to your last comment ?
    So for 8.0.7, will it be fixed? If so, does that mean not before mid-August at the earliest?
    Thanks in advance for any answer. This is an issue in our production environment.

  18. lambdageek commented on Jul 9, 2024

    @lambdageek
    Member

    .NET 8.0.7 is out today. I verified that the crash is fixed in this release. (.NET 9 Preview 6 also works)

  19. locked and limited conversation to collaborators on Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions