dotnet / dotnet/runtime

[browser][CoreCLR] doesn't support PInvoke in custom app/library

Open
#131,874 5 comments 0 reactions 1 assignee Claimed by @radekdoulik View on GitHub
arch-wasm area-Host
Dominant language
C#
Stars
18.3k
Forks
5.6k
PR merge metrics
PR metrics pending

Description

### Description

Trying to use CoreCLR+WebAssembly along with native assets results in build failures.

`WASM0067: SignatureMapper: unknown multi-field struct`

(Filing this [at the request of](https://discord.com/channels/732297728826277939/732297825731215521/1534197541590274241) @pavelsavara )

### Reproduction Steps

Use .NET 11 Preview 6 (Linux, Windows) or Preview 7 (macOS; see #131799) or later.

Create a `blazorwasm` project, and add NuGet dependencies for SkiaSharp, use a type from SkiaSharp, and set `$(UseMonoRuntime)`=false:

```sh
dotnet new blazorwasm -o net11+blazor+coreclr+native
cd net11+blazor+coreclr+native
dotnet package add SkiaSharp -v 4.151.0
dotnet package add SkiaSharp.NativeAssets.WebAssembly -v 4.151.0
cat <<'EOF' | git apply
diff --git a/Program.cs b/Program.cs
index e4dbefc..1b42e63 100644
--- a/Program.cs
+++ b/Program.cs
@@ -2,6 +2,9 @@ using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using net11_blazor_coreclr_native;

+var path = new SkiaSharp.SKPath();
+Console.WriteLine($"# jonp: path.Bounds={path.Bounds}");
+
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add("#app");
builder.RootComponents.Add("head::after");
diff --git a/net11+blazor+coreclr+native.csproj b/net11+blazor+coreclr+native.csproj
index 0c0a2f8..2a47a07 100644
--- a/net11+blazor+coreclr+native.csproj
+++ b/net11+blazor+coreclr+native.csproj
@@ -6,6 +6,7 @@
enable
true
true
+ false



EOF
```

If on macOS, you need to be using the not-yet-released .NET 11 Preview 7, so create a `nuget.config` so that the relevant NuGet packages can be found:

```sh
cat <<'EOF' > nuget.config



EOF
```

Run the app:

```dotnetcli
dotnet run -bl
```

### Expected behavior

No errors, app runs.

For example, change `$(UseMonoRuntime)` to true, and `dotnet run` launches the app without error.

### Actual behavior

Many errors and warnings; see also [msbuild.binlog.zip](https://github.com/user-attachments/files/30747329/msbuild.binlog.zip):

```
…/dotnet-sdk-11.0.100-preview.7.26381.103/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/11.0.0-preview.7.26381.103/Sdk/BrowserWasmApp.CoreCLR.targets(633,5): error WASM0067: SignatureMapper: unknown multi-field struct 'SkiaSharp.GRD3DBackendContextNative' (fields: 5) — add its size to s_knownStructSizes in SignatureMapper.cs
…/dotnet-sdk-11.0.100-preview.7.26381.103/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/11.0.0-preview.7.26381.103/Sdk/BrowserWasmApp.CoreCLR.targets(633,5): warning WASM0001:
Could not get pinvoke, or callbacks for method 'SkiaSharp.SkiaApi::gr_direct_context_make_direct3d' because 'System.NotSupportedException: Unsupported parameter type in method 'SkiaSharp.SkiaApi.gr_direct_context_make_direct3d'
at Microsoft.WebAssembly.Build.Tasks.CoreClr.PInvokeCollector.g__CollectPInvokesForMethod|9_0(MethodInfo method, <>c__DisplayClass9_0&)
at Microsoft.WebAssembly.Build.Tasks.CoreClr.PInvokeCollector.CollectPInvokes(List`1 pinvokes, List`1 callbacks, HashSet`1 signatures, Type type)'
…/dotnet-sdk-11.0.100-preview.7.26381.103/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/11.0.0-preview.7.26381.103/Sdk/BrowserWasmApp.CoreCLR.targets(633,5): error WASM0067: SignatureMapper: unknown multi-field struct 'SkiaSharp.GRD3DBackendContextNative' (fields: 5) — add its size to s_knownStructSizes in SignatureMapper.cs
…/dotnet-sdk-11.0.100-preview.7.26381.103/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/11.0.0-preview.7.26381.103/Sdk/BrowserWasmApp.CoreCLR.targets(633,5): warning WASM0001:
Could not get pinvoke, or callbacks for method 'SkiaSharp.SkiaApi::gr_direct_context_make_direct3d_with_options' because 'System.NotSupportedException: Unsupported parameter type in method 'SkiaSharp.SkiaApi.gr_direct_context_make_direct3d_with_options'
at Microsoft.WebAssembly.Build.Tasks.CoreClr.PInvokeCollector.g__CollectPInvokesForMethod|9_0(MethodInfo method, <>c__DisplayClass9_0&)
at Microsoft.WebAssembly.Build.Tasks.CoreClr.PInvokeCollector.CollectPInvokes(List`1 pinvokes, List`1 callbacks, HashSet`1 signatures, Type type)'
…/dotnet-sdk-11.0.100-preview.7.26381.103/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/11.0.0-preview.7.26381.103/Sdk/BrowserWasmApp.CoreCLR.targets(633,5): error WASM0067: SignatureMapper: unknown multi-field struct 'SkiaSharp.GRVkBackendContextNative' (fields: 13) — add its size to s_knownStructSizes in SignatureMapper.cs
…/dotnet-sdk-11.0.100-preview.7.26381.103/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/11.0.0-preview.7.26381.103/Sdk/BrowserWasmApp.CoreCLR.targets(633,5): warning WASM0001:
Could not get pinvoke, or callbacks for method 'SkiaSharp.SkiaApi::gr_direct_context_make_vulkan' because 'System.NotSupportedException: Unsupported parameter type in method 'SkiaSharp.SkiaApi.gr_direct_context_make_vulkan'
at Microsoft.WebAssembly.Build.Tasks.CoreClr.PInvokeCollector.g__CollectPInvokesForMethod|9_0(MethodInfo method, <>c__DisplayClass9_0&)
at Microsoft.WebAssembly.Build.Tasks.CoreClr.PInvokeCollector.CollectPInvokes(List`1 pinvokes, List`1 callbacks, HashSet`1 signatures, Type type)'
…/dotnet-sdk-11.0.100-preview.7.26381.103/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/11.0.0-preview.7.26381.103/Sdk/BrowserWasmApp.CoreCLR.targets(633,5): error WASM0067: SignatureMapper: unknown multi-field struct 'SkiaSharp.GRVkBackendContextNative' (fields: 13) — add its size to s_knownStructSizes in SignatureMapper.cs
…/dotnet-sdk-11.0.100-preview.7.26381.103/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/11.0.0-preview.7.26381.103/Sdk/BrowserWasmApp.CoreCLR.targets(633,5): warning WASM0001:
Could not get pinvoke, or callbacks for method 'SkiaSharp.SkiaApi::gr_direct_context_make_vulkan_with_options' because 'System.NotSupportedException: Unsupported parameter type in method 'SkiaSharp.SkiaApi.gr_direct_context_make_vulkan_with_options'
at Microsoft.WebAssembly.Build.Tasks.CoreClr.PInvokeCollector.g__CollectPInvokesForMethod|9_0(MethodInfo method, <>c__DisplayClass9_0&)
at Microsoft.WebAssembly.Build.Tasks.CoreClr.PInvokeCollector.CollectPInvokes(List`1 pinvokes, List`1 callbacks, HashSet`1 signatures, Type type)'
…/dotnet-sdk-11.0.100-preview.7.26381.103/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/11.0.0-preview.7.26381.103/Sdk/BrowserWasmApp.CoreCLR.targets(633,5): error WASM0067: SignatureMapper: unknown multi-field struct 'SkiaSharp.SKColorF' (fields: 4) — add its size to s_knownStructSizes in SignatureMapper.cs
…/dotnet-sdk-11.0.100-preview.7.26381.103/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/11.0.0-preview.7.26381.103/Sdk/BrowserWasmApp.CoreCLR.targets(633,5): warning WASM0001:
Could not get pinvoke, or callbacks for method 'SkiaSharp.SkiaApi::sk_canvas_clear_color4f' because 'System.NotSupportedException: Unsupported parameter type in method 'SkiaSharp.SkiaApi.sk_canvas_clear_color4f'
at Microsoft.WebAssembly.Build.Tasks.CoreClr.PInvokeCollector.g__CollectPInvokesForMethod|9_0(MethodInfo method, <>c__DisplayClass9_0&)
at Microsoft.WebAssembly.Build.Tasks.CoreClr.PInvokeCollector.CollectPInvokes(List`1 pinvokes, List`1 callbacks, HashSet`1 signatures, Type type)'
…/dotnet-sdk-11.0.100-preview.7.26381.103/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/11.0.0-preview.7.26381.103/Sdk/BrowserWasmApp.CoreCLR.targets(633,5): error WASM0067: SignatureMapper: unknown multi-field struct 'SkiaSharp.SKColorF' (fields: 4) — add its size to s_knownStructSizes in SignatureMapper.cs
…/dotnet-sdk-11.0.100-preview.7.26381.103/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/11.0.0-preview.7.26381.103/Sdk/BrowserWasmApp.CoreCLR.targets(633,5): warning WASM0001:
Could not get pinvoke, or callbacks for method 'SkiaSharp.SkiaApi::sk_canvas_draw_color4f' because 'System.NotSupportedException: Unsupported parameter type in method 'SkiaSharp.SkiaApi.sk_canvas_draw_color4f'
at Microsoft.WebAssembly.Build.Tasks.CoreClr.PInvokeCollector.g__CollectPInvokesForMethod|9_0(MethodInfo method, <>c__DisplayClass9_0&)
at Microsoft.WebAssembly.Build.Tasks.CoreClr.PInvokeCollector.CollectPInvokes(List`1 pinvokes, List`1 callbacks, HashSet`1 signatures, Type type)'
…/dotnet-sdk-11.0.100-preview.7.26381.103/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/11.0.0-preview.7.26381.103/Sdk/BrowserWasmApp.CoreCLR.targets(633,5): error WASM0067: SignatureMapper: unknown multi-field struct 'SkiaSharp.SKManagedDrawableDelegates' (fields: 5) — add its size to s_knownStructSizes in SignatureMapper.cs
…/dotnet-sdk-11.0.100-preview.7.26381.103/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/11.0.0-preview.7.26381.103/Sdk/BrowserWasmApp.CoreCLR.targets(633,5): warning WASM0001:
Could not get pinvoke, or callbacks for method 'SkiaSharp.SkiaApi::sk_manageddrawable_set_procs' because 'System.NotSupportedException: Unsupported parameter type in method 'SkiaSharp.SkiaApi.sk_manageddrawable_set_procs'
at Microsoft.WebAssembly.Build.Tasks.CoreClr.PInvokeCollector.g__CollectPInvokesForMethod|9_0(MethodInfo method, <>c__DisplayClass9_0&)
at Microsoft.WebAssembly.Build.Tasks.CoreClr.PInvokeCollector.CollectPInvokes(List`1 pinvokes, List`1 callbacks, HashSet`1 signatures, Type type)'
…/dotnet-sdk-11.0.100-preview.7.26381.103/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/11.0.0-preview.7.26381.103/Sdk/BrowserWasmApp.CoreCLR.targets(633,5): error WASM0067: SignatureMapper: unknown multi-field struct 'SkiaSharp.SKManagedStreamDelegates' (fields: 13) — add its size to s_knownStructSizes in SignatureMapper.cs
…/dotnet-sdk-11.0.100-preview.7.26381.103/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/11.0.0-preview.7.26381.103/Sdk/BrowserWasmApp.CoreCLR.targets(633,5): warning WASM0001:
Could not get pinvoke, or callbacks for method 'SkiaSharp.SkiaApi::sk_managedstream_set_procs' because 'System.NotSupportedException: Unsupported parameter type in method 'SkiaSharp.SkiaApi.sk_managedstream_set_procs'
at Microsoft.WebAssembly.Build.Tasks.CoreClr.PInvokeCollector.g__CollectPInvokesForMethod|9_0(MethodInfo method, <>c__DisplayClass9_0&)
at Microsoft.WebAssembly.Build.Tasks.CoreClr.PInvokeCollector.CollectPInvokes(List`1 pinvokes, List`1 callbacks, HashSet`1 signatures, Type type)'
…/dotnet-sdk-11.0.100-preview.7.26381.103/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/11.0.0-preview.7.26381.103/Sdk/BrowserWasmApp.CoreCLR.targets(633,5): error WASM0067: SignatureMapper: unknown multi-field struct 'SkiaSharp.SKManagedWStreamDelegates' (fields: 4) — add its size to s_knownStructSizes in SignatureMapper.cs
…/dotnet-sdk-11.0.100-preview.7.26381.103/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/11.0.0-preview.7.26381.103/Sdk/BrowserWasmApp.CoreCLR.targets(633,5): warning WASM0001:
Could not get pinvoke, or callbacks for method 'SkiaSharp.SkiaApi::sk_managedwstream_set_procs' because 'System.NotSupportedException: Unsupported parameter type in method 'SkiaSharp.SkiaApi.sk_managedwstream_set_procs'
at Microsoft.WebAssembly.Build.Tasks.CoreClr.PInvokeCollector.g__CollectPInvokesForMethod|9_0(MethodInfo method, <>c__DisplayClass9_0&)
at Microsoft.WebAssembly.Build.Tasks.CoreClr.PInvokeCollector.CollectPInvokes(List`1 pinvokes, List`1 callbacks, HashSet`1 signatures, Type type)'
…/dotnet-sdk-11.0.100-preview.7.26381.103/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/11.0.0-preview.7.26381.103/Sdk/BrowserWasmApp.CoreCLR.targets(633,5): error WASM0067: SignatureMapper: unknown multi-field struct 'SkiaSharp.SKManagedTraceMemoryDumpDelegates' (fields: 2) — add its size to s_knownStructSizes in SignatureMapper.cs
…/dotnet-sdk-11.0.100-preview.7.26381.103/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/11.0.0-preview.7.26381.103/Sdk/BrowserWasmApp.CoreCLR.targets(633,5): warning WASM0001:
Could not get pinvoke, or callbacks for method 'SkiaSharp.SkiaApi::sk_managedtracememorydump_set_procs' because 'System.NotSupportedException: Unsupported parameter type in method 'SkiaSharp.SkiaApi.sk_managedtracememorydump_set_procs'
at Microsoft.WebAssembly.Build.Tasks.CoreClr.PInvokeCollector.g__CollectPInvokesForMethod|9_0(MethodInfo method, <>c__DisplayClass9_0&)
at Microsoft.WebAssembly.Build.Tasks.CoreClr.PInvokeCollector.CollectPInvokes(List`1 pinvokes, List`1 callbacks, HashSet`1 signatures, Type type)'
…/dotnet-sdk-11.0.100-preview.7.26381.103/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/11.0.0-preview.7.26381.103/Sdk/BrowserWasmApp.CoreCLR.targets(633,5): warning WASM0066: PInvoke module 'ole32.dll' for method 'SkiaSharp.SKAutoCoInitialize::g____PInvoke|12_0' is not in the list of allowed modules. It is also not a specially treated module.
…/dotnet-sdk-11.0.100-preview.7.26381.103/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/11.0.0-preview.7.26381.103/Sdk/BrowserWasmApp.CoreCLR.targets(633,5): warning WASM0066: PInvoke module 'ole32.dll' for method 'SkiaSharp.SKAutoCoInitialize::g____PInvoke|13_0' is not in the list of allowed modules. It is also not a specially treated module.
…/dotnet-sdk-11.0.100-preview.7.26381.103/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/11.0.0-preview.7.26381.103/Sdk/BrowserWasmApp.CoreCLR.targets(633,5): warning WASM0066: PInvoke module 'libc' for method 'SkiaSharp.Internals.PlatformConfiguration::gnu_get_libc_version' is not in the list of allowed modules. It is also not a specially treated module.
…/dotnet-sdk-11.0.100-preview.7.26381.103/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/11.0.0-preview.7.26381.103/Sdk/BrowserWasmApp.CoreCLR.targets(633,5): warning WASM0066: PInvoke module 'Kernel32.dll' for method 'SkiaSharp.GRGlInterface+AngleLoader::g____PInvoke|2_0' is not in the list of allowed modules. It is also not a specially treated module.
…/dotnet-sdk-11.0.100-preview.7.26381.103/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/11.0.0-preview.7.26381.103/Sdk/BrowserWasmApp.CoreCLR.targets(633,5): warning WASM0066: PInvoke module 'Kernel32.dll' for method 'SkiaSharp.GRGlInterface+AngleLoader::g____PInvoke|3_0' is not in the list of allowed modules. It is also not a specially treated module.
…/dotnet-sdk-11.0.100-preview.7.26381.103/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/11.0.0-preview.7.26381.103/Sdk/BrowserWasmApp.CoreCLR.targets(633,5): warning WASM0066: PInvoke module 'libEGL.dll' for method 'SkiaSharp.GRGlInterface+AngleLoader::g____PInvoke|4_0' is not in the list of allowed modules. It is also not a specially treated module.
…/dotnet-sdk-11.0.100-preview.7.26381.103/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/11.0.0-preview.7.26381.103/Sdk/BrowserWasmApp.CoreCLR.targets(633,5): warning WASM0066: PInvoke module 'Kernel32.dll' for method 'SkiaSharp.Internals.PlatformLock+NonAlertableWin32Lock::DeleteCriticalSection' is not in the list of allowed modules. It is also not a specially treated module.
…/dotnet-sdk-11.0.100-preview.7.26381.103/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/11.0.0-preview.7.26381.103/Sdk/BrowserWasmApp.CoreCLR.targets(633,5): warning WASM0066: PInvoke module 'Kernel32.dll' for method 'SkiaSharp.Internals.PlatformLock+NonAlertableWin32Lock::EnterCriticalSection' is not in the list of allowed modules. It is also not a specially treated module.
…/dotnet-sdk-11.0.100-preview.7.26381.103/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/11.0.0-preview.7.26381.103/Sdk/BrowserWasmApp.CoreCLR.targets(633,5): warning WASM0066: PInvoke module 'Kernel32.dll' for method 'SkiaSharp.Internals.PlatformLock+NonAlertableWin32Lock::LeaveCriticalSection' is not in the list of allowed modules. It is also not a specially treated module.
…/dotnet-sdk-11.0.100-preview.7.26381.103/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/11.0.0-preview.7.26381.103/Sdk/BrowserWasmApp.CoreCLR.targets(633,5): warning WASM0066: PInvoke module 'Kernel32.dll' for method 'SkiaSharp.Internals.PlatformLock+NonAlertableWin32Lock::g____PInvoke|12_0' is not in the list of allowed modules. It is also not a specially treated module.
```

### Regression?

No, as CoreCLR+WebAssembly is a new feature.

### Known Workarounds

Continue using MonoVM.

### Configuration

[.NET 11 Preview 7.](https://aka.ms/dotnet/11.0.1xx-preview7/daily/dotnet-sdk-osx-arm64.tar.gz) / dotnet-sdk-11.0.100-preview.7.26381.103
macOS 26.6
arm64

### Other information

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.