Uno.Wasm.Bootstrap
Uno.Wasm.Bootstrap copied to clipboard
Enabling threads on wasm preview causes skiasharp fail to load
Current behavior
Launching project results in the uno logo splash screen to stay up and console to print error about libSkiaSharp failing to load:
fail: Uno.UI.Dispatching.CoreDispatcher[0]
Dispatcher unhandled exception
System.InvalidOperationException: Failed to load VS2022SkiaError.MainPage: System.TypeInitializationException: TypeInitialization_Type, SkiaSharp.SKImageInfo
---> System.DllNotFoundException: libSkiaSharp
at SkiaSharp.SKImageInfo..cctor() in D:\a\1\s\binding\Binding\SKImageInfo.cs:line 46
Exception_EndOfInnerExceptionStack
at VS2022SkiaError.MainPage..ctor() in C:\source\VS2022SkiaError\VS2022SkiaError\VS2022SkiaError.Wasm\Uno.UI.SourceGenerators\Uno.UI.SourceGenerators.XamlGenerator.XamlCodeGenerator\MainPage_2dd2af64094792981fb43b8c6148227d.cs:line 26
at VS2022SkiaError.Wasm.MetadataBuilder_573.CreateInstance() in C:\source\VS2022SkiaError\VS2022SkiaError\VS2022SkiaError.Wasm\Uno.UI.SourceGenerators\Uno.UI.SourceGenerators.BindableTypeProviders.BindableTypeProvidersSourceGenerator\BindableMetadata.cs:line 20964
at Microsoft.UI.Xaml.Controls.Frame.CreatePageInstance(Type sourcePageType) in C:\a\1\s\src\Uno.UI\UI\Xaml\Controls\Frame\Frame.cs:line 445
at Microsoft.UI.Xaml.PagePool.DequeuePage(Type pageType) in C:\a\1\s\src\Uno.UI\UI\Xaml\PagePool.cs:line 69
at Microsoft.UI.Xaml.Controls.Frame.CreatePageInstanceCached(Type sourcePageType) in C:\a\1\s\src\Uno.UI\UI\Xaml\Controls\Frame\Frame.cs:line 435
at Microsoft.UI.Xaml.Controls.Frame.InnerNavigate(PageStackEntry entry, NavigationMode mode) in C:\a\1\s\src\Uno.UI\UI\Xaml\Controls\Frame\Frame.cs:line 283
at VS2022SkiaError.App.OnNavigationFailed(Object sender, NavigationFailedEventArgs e) in C:\source\VS2022SkiaError\VS2022SkiaError\VS2022SkiaError.Shared\App.xaml.cs:line 97
at Microsoft.UI.Xaml.Controls.Frame.InnerNavigate(PageStackEntry entry, NavigationMode mode) in C:\a\1\s\src\Uno.UI\UI\Xaml\Controls\Frame\Frame.cs:line 300
at Microsoft.UI.Xaml.Controls.Frame.Navigate(Type sourcePageType, Object parameter, NavigationTransitionInfo infoOverride) in C:\a\1\s\src\Uno.UI\UI\Xaml\Controls\Frame\Frame.cs:line 276
at Microsoft.UI.Xaml.Controls.Frame.Navigate(Type sourcePageType, Object parameter) in C:\a\1\s\src\Uno.UI\UI\Xaml\Controls\Frame\Frame.cs:line 271
at VS2022SkiaError.App.OnLaunched(LaunchActivatedEventArgs args) in C:\source\VS2022SkiaError\VS2022SkiaError\VS2022SkiaError.Shared\App.xaml.cs:line 83
at Microsoft.UI.Xaml.Application.Initialize() in C:\a\1\s\src\Uno.UI\UI\Xaml\Application.wasm.cs:line 130
at Uno.UI.Dispatching.CoreDispatcher.InvokeOperationSafe(UIAsyncOperation operation) in C:\a\1\s\src\Uno.UI.Dispatching\Core\CoreDispatcher.cs:line 337
Expected behavior
Libraries load correctly when threading is enabled.
How to reproduce it (as minimally and precisely as possible)
update to preview uno wasm, enable threading, try creating a bitmap in MainPage.xaml.cs VS2022SkiaError.zip
Workaround
Don't enable threading
Works on UWP/WinUI
No response
Environment
No response
NuGet package version(s)
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
<PackageReference Include="SkiaSharp.Views.Uno.WinUI" Version="2.88.1-preview.58" />
<PackageReference Include="Uno.Extensions.Logging.WebAssembly.Console" Version="1.3.0" />
<PackageReference Include="Uno.WinUI.WebAssembly" Version="4.5.0-dev.95" />
<PackageReference Include="Uno.WinUI.RemoteControl" Version="4.5.0-dev.95" Condition="'$(Configuration)'=='Debug'" />
<PackageReference Include="Uno.UI.Adapter.Microsoft.Extensions.Logging" Version="4.5.0-dev.306" />
<PackageReference Include="Uno.Wasm.Bootstrap" Version="4.0.0-dev.174" />
<PackageReference Include="Uno.Wasm.Bootstrap.DevServer" Version="4.0.0-dev.174" />
Affected platforms
WebAssembly
IDE
Visual Studio 2022
IDE version
17.3.0 Preview 3.0
Relevant plugins
No response
Anything else we need to know?
This is just speculation, but it could be due to a single library failing to load, causing all libraries to fail at once. I experienced the same issue including a self compiled .bc static library, which was done on an older emscripten(so I assume it failed to load due to that). After upgrading emscripten to latest version and recompiling the project worked correctly, not showing the libSkiaSharp error and allowing me to call both skiasharp and the self compiled library.
Thanks for the report. Indeed, SkiaSharp needs to be built using threading enabled (or with a specific set of options to make it compatible). The Wasm Boostrapper needs to understand how to select threading and non-threading versions of the binaries, something that is not yet available.
Will be fixed by https://github.com/mono/SkiaSharp/pull/2259