Mapsui icon indicating copy to clipboard operation
Mapsui copied to clipboard

Blazor map control crashes when AOT compiled

Open p2pbsh opened this issue 1 year ago • 8 comments

Mapsui Version 5 beta 1, 5 beta 2

Mapsui Platform Blazor

Device Windows 10, Microsoft Edge browser.

Describe the bug When publishing a blazor project with AOT disabled, mapsui map control works correctly. Publishing same project with AOT enabled, map control fails to render and throws an unhandled exception.

To Reproduce Steps to reproduce the behavior:

  1. Create a new blazor project using standard web app template, with wasm render mode configured.
  2. Add mapsui map control component to any wasm page, just attempting to render the basic component is all that is needed.
  3. Enable AOT option in project
  4. Publish and run app.

Expected behavior Map control renders on page.

Screenshots error

Additional context Map control fails to render and I get the above exception in the browser developer console. Call stack is not particularly helpful, only thing that seems applicable are some references to skia canvas rendering, but don't really understand what I'm looking at.

p2pbsh avatar Jul 09 '24 19:07 p2pbsh

@inforithmics

p2pbsh avatar Jul 09 '24 19:07 p2pbsh

Have you tried targeting .NET 9 Preview (Has some AOT Improvements)

inforithmics avatar Jul 09 '24 20:07 inforithmics

I have not, will give it a go. Was just curious or after some independent confirmation that the map control should AOT ok in mapsui 5?

p2pbsh avatar Jul 09 '24 20:07 p2pbsh

Theoretically yes. But the publish for the Sample Page the AOT is currently disabled. For testing i enabled AOT and it still worked. So that's why I'm asking for a sample that reproduces the behavior.

inforithmics avatar Jul 09 '24 22:07 inforithmics

There you go boss

  • cd ..\MapAotTest\MapAotTest\MapAotTest
  • dotnet publish -c Release -o ./pub
  • http://localhost:5000

Two publish configs in MapAotTest.Client.csproj, config 1 works, config 2 produces the error I described.

MapAotTest.zip

p2pbsh avatar Jul 10 '24 08:07 p2pbsh

  1. I compiled it with .NET 9 (SkiaSharp caused an AOT Compile Error) so it seems SkiaSharp in Version 2.88 is not AOT Comptible yet. So SkiaSharp needs to be updated to 3.0.0
  2. I reproduced the call stack for me it seems to be a tooling problem possible related to SkiaSharp see above.

So at the moment it seems not to be 100% compatible with AOT because of Third Party dependencies (SkiaSharp), So when SkiaSharp is released in Version 3.0.0 I could have a look at it again, Currently I cannot do so much.

inforithmics avatar Jul 13 '24 09:07 inforithmics

With .Net 9 and SkiaSharp 3 (Beta) in AOT following Compilation Error occours MapAotTest.Client fehlerhaft mit 1 Fehler(n) (24.8s)

C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\9.0.0-preview.6.24327.7\Sdk\WasmApp.Common.targets(692,5): error :
    Precompiling failed for D:\MapAotTest\MapAotTest\MapAotTest.Client\obj\Release\net9.0\wasm\for-publish\aot-in\Skia
    Sharp.Views.Blazor.dll with exit code -1073741819.
    Mono Ahead of Time compiler - compiling assembly D:\MapAotTest\MapAotTest\MapAotTest.Client\obj\Release\net9.0\was
    m\for-publish\aot-in\SkiaSharp.Views.Blazor.dll
    Could not load signature of SkiaSharp.Views.Blazor.Internal.JSModuleInterop:get_Module due to: Could not resolve t
    ype with token 0100003b from typeref (expected class 'Microsoft.JSInterop.IJSUnmarshalledObjectReference' in assem
    bly 'Microsoft.JSInterop, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60') assembly:Microsoft.J
    SInterop, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60 type:Microsoft.JSInterop.IJSUnmarshall
    edObjectReference member:(null)
    Could not load signature of SkiaSharp.Views.Blazor.Internal.JSModuleInterop:get_Module due to: Could not resolve t
    ype with token 0100003b from typeref (expected class 'Microsoft.JSInterop.IJSUnmarshalledObjectReference' in assem
    bly 'Microsoft.JSInterop, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60') assembly:Microsoft.J
    SInterop, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60 type:Microsoft.JSInterop.IJSUnmarshall
    edObjectReference member:(null)
    Failed to load methodspec 0x2b000009 due to Could not resolve type with token 0100003b from typeref (expected clas
    s 'Microsoft.JSInterop.IJSUnmarshalledObjectReference' in assembly 'Microsoft.JSInterop, Version=6.0.0.0, Culture=
    neutral, PublicKeyToken=adb9793829ddae60') assembly:Microsoft.JSInterop, Version=6.0.0.0, Culture=neutral, PublicK
    eyToken=adb9793829ddae60 type:Microsoft.JSInterop.IJSUnmarshalledObjectReference member:(null).
    Run with MONO_LOG_LEVEL=debug for more information.
    Failed to load methodspec 0x2b000018 due to Could not resolve type with token 0100003b from typeref (expected clas
    s 'Microsoft.JSInterop.IJSUnmarshalledObjectReference' in assembly 'Microsoft.JSInterop, Version=6.0.0.0, Culture=
    neutral, PublicKeyToken=adb9793829ddae60') assembly:Microsoft.JSInterop, Version=6.0.0.0, Culture=neutral, PublicK
    eyToken=adb9793829ddae60 type:Microsoft.JSInterop.IJSUnmarshalledObjectReference member:(null).
    Run with MONO_LOG_LEVEL=debug for more information.
MapAotTest Fehlgeschlagen (1.2s) → bin\Release\net9.0\MapAotTest.dll

So I think this could be the problem why it doesn't start up because jsinterop is important for webassembly functionality, I think when SkiaSharp is updated to .NET 8 this sould be solved.

https://github.com/mono/SkiaSharp/pull/2927

inforithmics avatar Jul 13 '24 10:07 inforithmics

Thanks for taking a look and shinning some light on the issue.

I have mapsui built into my blazor app now and its awesome, just this one issue blocking me giving the app the AOT perf boost it needs. Fingers crossed skia 3 resolves, cheers fella.

p2pbsh avatar Jul 13 '24 11:07 p2pbsh

Working great now in beta 7.

p2pbsh avatar Jan 11 '25 14:01 p2pbsh