Skip to content

[WASM] callback fron native code to .Net: Parsing function pointer types in signatures is not supported #56145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
emepetres opened this issue Jul 22, 2021 · 12 comments
Assignees
Labels
arch-wasm WebAssembly architecture area-Build-mono area-Interop-mono blocked Issue/PR is blocked on something - see comments
Milestone

Comments

@emepetres
Copy link

I'm trying to do a call from .Net a native function which call backs to .Net. I'm using function pointers as suggested in discord channel, but I'm getting the following error (maybe related to #43791?):

1:7>Target "_GeneratePInvokeTable: (TargetId:229)" in file "C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets" from project "C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj" (target "_WasmBuildNativeCore" depends on it):
                   Added Item(s): _WasmPInvokeModules=libWasmNative
                   Added Item(s): _WasmPInvokeModules=libSystem.Native
                   Added Item(s): _WasmPInvokeModules=libSystem.IO.Compression.Native
                   Added Item(s): _WasmPInvokeModules=libSystem.Globalization.Native
                   Using "PInvokeTableGenerator" task from assembly "C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\..\tasks\net6.0\WasmAppBuilder.dll".
                   Task "PInvokeTableGenerator" (TaskId:151)
                     Task Parameter:
                         Assemblies=
                             C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\obj\Debug\net6.0\linked\Wasm.Console.Sample.dll
                             C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\obj\Debug\net6.0\linked\System.Console.dll
                             C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\obj\Debug\net6.0\linked\System.Private.Runtime.InteropServices.JavaScript.dll
                             C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\obj\Debug\net6.0\linked\System.Private.Uri.dll
                             C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\obj\Debug\net6.0\linked\System.Runtime.CompilerServices.Unsafe.dll
                             C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\obj\Debug\net6.0\linked\System.Runtime.dll
                             C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\obj\Debug\net6.0\linked\System.Private.CoreLib.dll (TaskId:151)
                     Task Parameter:OutputPath=C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\obj\Debug\net6.0\wasm\pinvoke-table.h (TaskId:151)
                     Task Parameter:
                         Modules=
                             libWasmNative
                             libSystem.Native
                             libSystem.IO.Compression.Native
                             libSystem.Globalization.Native (TaskId:151)
                     Generating pinvoke table to 'C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\obj\Debug\net6.0\wasm\pinvoke-table.h'. (TaskId:151)
13:27:49.489   1:7>C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018: The "PInvokeTableGenerator" task failed unexpectedly. [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018: System.NotSupportedException: Parsing function pointer types in signatures is not supported. [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018:    at System.Reflection.TypeLoading.Ecma.EcmaModule.GetFunctionPointerType(MethodSignature`1 signature) in System.Reflection.MetadataLoadContext.dll:token 0x6000619+0xa [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018:    at System.Reflection.Metadata.Ecma335.SignatureDecoder`2.DecodeType(BlobReader& blobReader, Boolean allowTypeSpecifications, Int32 typeCode) in System.Reflection.Metadata.dll:token 0x6000abf+0x100 [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018:    at System.Reflection.Metadata.Ecma335.SignatureDecoder`2.DecodeMethodSignature(BlobReader& blobReader) in System.Reflection.Metadata.dll:token 0x6000ac1+0x5a [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018:    at System.Reflection.TypeLoading.Ecma.EcmaMethodDecoder.SpecializeMethodSig(IRoMethodBase roMethodBase) in System.Reflection.MetadataLoadContext.dll:token 0x60005e8+0x0 [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018:    at System.Reflection.TypeLoading.RoDefinitionMethod`1.ComputeMethodSig() in System.Reflection.MetadataLoadContext.dll:token 0x6000245+0x7 [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018:    at System.Reflection.TypeLoading.RoMethod.get_MethodSig() in System.Reflection.MetadataLoadContext.dll:token 0x6000278+0xc [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018:    at System.Reflection.TypeLoading.RoMethod.get_ReturnParameter() in System.Reflection.MetadataLoadContext.dll:token 0x6000276+0x0 [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018:    at System.Reflection.TypeLoading.RoMethod.get_ReturnType() in System.Reflection.MetadataLoadContext.dll:token 0x600027d+0x0 [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018:    at PInvokeTableGenerator.GenPInvokeDecl(PInvoke pinvoke) in WasmAppBuilder.dll:token 0x6000020+0xc9 [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018:    at PInvokeTableGenerator.EmitPInvokeTable(StreamWriter w, Dictionary`2 modules, List`1 pinvokes) in WasmAppBuilder.dll:token 0x600001e+0x59 [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018:    at PInvokeTableGenerator.GenPInvokeTable(String[] pinvokeModules, String[] assemblies) in WasmAppBuilder.dll:token 0x600001c+0xaf [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018:    at PInvokeTableGenerator.Execute() in WasmAppBuilder.dll:token 0x600001b+0x75 [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() in Microsoft.Build.dll:token 0x60015fb+0x3e [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) in Microsoft.Build.dll:token 0x600147a+0x2b5 [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
                   Done executing task "PInvokeTableGenerator" -- FAILED. (TaskId:151)

This are the most relevants parts of the code:

[DllImport(DllName)]
public static extern unsafe void callCbk(delegate*<void> cbk);
typedef void (*callback)(void);

void callCbk(callback cbk)
{
    cbk();
}

And I'm using version

  Microsoft.AspNetCore.App 6.0.0-rc.1.21370.12 [C:\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.0-rc.1.21369.14 [C:\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 6.0.0-rc.1.21369.7 [C:\dotnet\shared\Microsoft.WindowsDesktop.App]
@ghost ghost added area-HostModel Microsoft.NET.HostModel issues untriaged New issue has not been triaged by the area owner labels Jul 22, 2021
@ghost
Copy link

ghost commented Jul 22, 2021

Tagging subscribers to this area: @vitek-karas, @agocke
See info in area-owners.md if you want to be subscribed.

Issue Details

I'm trying to do a call from .Net a native function which call backs to .Net. I'm using function pointers as suggested in discord channel, but I'm getting the following error (maybe related to #43791?):

1:7>Target "_GeneratePInvokeTable: (TargetId:229)" in file "C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets" from project "C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj" (target "_WasmBuildNativeCore" depends on it):
                   Added Item(s): _WasmPInvokeModules=libWasmNative
                   Added Item(s): _WasmPInvokeModules=libSystem.Native
                   Added Item(s): _WasmPInvokeModules=libSystem.IO.Compression.Native
                   Added Item(s): _WasmPInvokeModules=libSystem.Globalization.Native
                   Using "PInvokeTableGenerator" task from assembly "C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\..\tasks\net6.0\WasmAppBuilder.dll".
                   Task "PInvokeTableGenerator" (TaskId:151)
                     Task Parameter:
                         Assemblies=
                             C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\obj\Debug\net6.0\linked\Wasm.Console.Sample.dll
                             C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\obj\Debug\net6.0\linked\System.Console.dll
                             C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\obj\Debug\net6.0\linked\System.Private.Runtime.InteropServices.JavaScript.dll
                             C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\obj\Debug\net6.0\linked\System.Private.Uri.dll
                             C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\obj\Debug\net6.0\linked\System.Runtime.CompilerServices.Unsafe.dll
                             C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\obj\Debug\net6.0\linked\System.Runtime.dll
                             C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\obj\Debug\net6.0\linked\System.Private.CoreLib.dll (TaskId:151)
                     Task Parameter:OutputPath=C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\obj\Debug\net6.0\wasm\pinvoke-table.h (TaskId:151)
                     Task Parameter:
                         Modules=
                             libWasmNative
                             libSystem.Native
                             libSystem.IO.Compression.Native
                             libSystem.Globalization.Native (TaskId:151)
                     Generating pinvoke table to 'C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\obj\Debug\net6.0\wasm\pinvoke-table.h'. (TaskId:151)
13:27:49.489   1:7>C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018: The "PInvokeTableGenerator" task failed unexpectedly. [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018: System.NotSupportedException: Parsing function pointer types in signatures is not supported. [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018:    at System.Reflection.TypeLoading.Ecma.EcmaModule.GetFunctionPointerType(MethodSignature`1 signature) in System.Reflection.MetadataLoadContext.dll:token 0x6000619+0xa [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018:    at System.Reflection.Metadata.Ecma335.SignatureDecoder`2.DecodeType(BlobReader& blobReader, Boolean allowTypeSpecifications, Int32 typeCode) in System.Reflection.Metadata.dll:token 0x6000abf+0x100 [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018:    at System.Reflection.Metadata.Ecma335.SignatureDecoder`2.DecodeMethodSignature(BlobReader& blobReader) in System.Reflection.Metadata.dll:token 0x6000ac1+0x5a [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018:    at System.Reflection.TypeLoading.Ecma.EcmaMethodDecoder.SpecializeMethodSig(IRoMethodBase roMethodBase) in System.Reflection.MetadataLoadContext.dll:token 0x60005e8+0x0 [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018:    at System.Reflection.TypeLoading.RoDefinitionMethod`1.ComputeMethodSig() in System.Reflection.MetadataLoadContext.dll:token 0x6000245+0x7 [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018:    at System.Reflection.TypeLoading.RoMethod.get_MethodSig() in System.Reflection.MetadataLoadContext.dll:token 0x6000278+0xc [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018:    at System.Reflection.TypeLoading.RoMethod.get_ReturnParameter() in System.Reflection.MetadataLoadContext.dll:token 0x6000276+0x0 [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018:    at System.Reflection.TypeLoading.RoMethod.get_ReturnType() in System.Reflection.MetadataLoadContext.dll:token 0x600027d+0x0 [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018:    at PInvokeTableGenerator.GenPInvokeDecl(PInvoke pinvoke) in WasmAppBuilder.dll:token 0x6000020+0xc9 [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018:    at PInvokeTableGenerator.EmitPInvokeTable(StreamWriter w, Dictionary`2 modules, List`1 pinvokes) in WasmAppBuilder.dll:token 0x600001e+0x59 [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018:    at PInvokeTableGenerator.GenPInvokeTable(String[] pinvokeModules, String[] assemblies) in WasmAppBuilder.dll:token 0x600001c+0xaf [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018:    at PInvokeTableGenerator.Execute() in WasmAppBuilder.dll:token 0x600001b+0x75 [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() in Microsoft.Build.dll:token 0x60015fb+0x3e [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) in Microsoft.Build.dll:token 0x600147a+0x2b5 [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
                   Done executing task "PInvokeTableGenerator" -- FAILED. (TaskId:151)

This are the most relevants parts of the code:

[DllImport(DllName)]
public static extern unsafe void callCbk(delegate*<void> cbk);
typedef void (*callback)(void);

void callCbk(callback cbk)
{
    cbk();
}

And I'm using version

  Microsoft.AspNetCore.App 6.0.0-rc.1.21370.12 [C:\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.0-rc.1.21369.14 [C:\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 6.0.0-rc.1.21369.7 [C:\dotnet\shared\Microsoft.WindowsDesktop.App]
Author: emepetres
Assignees: -
Labels:

area-HostModel, untriaged

Milestone: -

@vitek-karas vitek-karas added the arch-wasm WebAssembly architecture label Jul 22, 2021
@ghost
Copy link

ghost commented Jul 22, 2021

Tagging subscribers to 'arch-wasm': @lewing
See info in area-owners.md if you want to be subscribed.

Issue Details

I'm trying to do a call from .Net a native function which call backs to .Net. I'm using function pointers as suggested in discord channel, but I'm getting the following error (maybe related to #43791?):

1:7>Target "_GeneratePInvokeTable: (TargetId:229)" in file "C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets" from project "C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj" (target "_WasmBuildNativeCore" depends on it):
                   Added Item(s): _WasmPInvokeModules=libWasmNative
                   Added Item(s): _WasmPInvokeModules=libSystem.Native
                   Added Item(s): _WasmPInvokeModules=libSystem.IO.Compression.Native
                   Added Item(s): _WasmPInvokeModules=libSystem.Globalization.Native
                   Using "PInvokeTableGenerator" task from assembly "C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\..\tasks\net6.0\WasmAppBuilder.dll".
                   Task "PInvokeTableGenerator" (TaskId:151)
                     Task Parameter:
                         Assemblies=
                             C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\obj\Debug\net6.0\linked\Wasm.Console.Sample.dll
                             C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\obj\Debug\net6.0\linked\System.Console.dll
                             C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\obj\Debug\net6.0\linked\System.Private.Runtime.InteropServices.JavaScript.dll
                             C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\obj\Debug\net6.0\linked\System.Private.Uri.dll
                             C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\obj\Debug\net6.0\linked\System.Runtime.CompilerServices.Unsafe.dll
                             C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\obj\Debug\net6.0\linked\System.Runtime.dll
                             C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\obj\Debug\net6.0\linked\System.Private.CoreLib.dll (TaskId:151)
                     Task Parameter:OutputPath=C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\obj\Debug\net6.0\wasm\pinvoke-table.h (TaskId:151)
                     Task Parameter:
                         Modules=
                             libWasmNative
                             libSystem.Native
                             libSystem.IO.Compression.Native
                             libSystem.Globalization.Native (TaskId:151)
                     Generating pinvoke table to 'C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\obj\Debug\net6.0\wasm\pinvoke-table.h'. (TaskId:151)
13:27:49.489   1:7>C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018: The "PInvokeTableGenerator" task failed unexpectedly. [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018: System.NotSupportedException: Parsing function pointer types in signatures is not supported. [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018:    at System.Reflection.TypeLoading.Ecma.EcmaModule.GetFunctionPointerType(MethodSignature`1 signature) in System.Reflection.MetadataLoadContext.dll:token 0x6000619+0xa [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018:    at System.Reflection.Metadata.Ecma335.SignatureDecoder`2.DecodeType(BlobReader& blobReader, Boolean allowTypeSpecifications, Int32 typeCode) in System.Reflection.Metadata.dll:token 0x6000abf+0x100 [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018:    at System.Reflection.Metadata.Ecma335.SignatureDecoder`2.DecodeMethodSignature(BlobReader& blobReader) in System.Reflection.Metadata.dll:token 0x6000ac1+0x5a [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018:    at System.Reflection.TypeLoading.Ecma.EcmaMethodDecoder.SpecializeMethodSig(IRoMethodBase roMethodBase) in System.Reflection.MetadataLoadContext.dll:token 0x60005e8+0x0 [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018:    at System.Reflection.TypeLoading.RoDefinitionMethod`1.ComputeMethodSig() in System.Reflection.MetadataLoadContext.dll:token 0x6000245+0x7 [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018:    at System.Reflection.TypeLoading.RoMethod.get_MethodSig() in System.Reflection.MetadataLoadContext.dll:token 0x6000278+0xc [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018:    at System.Reflection.TypeLoading.RoMethod.get_ReturnParameter() in System.Reflection.MetadataLoadContext.dll:token 0x6000276+0x0 [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018:    at System.Reflection.TypeLoading.RoMethod.get_ReturnType() in System.Reflection.MetadataLoadContext.dll:token 0x600027d+0x0 [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018:    at PInvokeTableGenerator.GenPInvokeDecl(PInvoke pinvoke) in WasmAppBuilder.dll:token 0x6000020+0xc9 [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018:    at PInvokeTableGenerator.EmitPInvokeTable(StreamWriter w, Dictionary`2 modules, List`1 pinvokes) in WasmAppBuilder.dll:token 0x600001e+0x59 [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018:    at PInvokeTableGenerator.GenPInvokeTable(String[] pinvokeModules, String[] assemblies) in WasmAppBuilder.dll:token 0x600001c+0xaf [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018:    at PInvokeTableGenerator.Execute() in WasmAppBuilder.dll:token 0x600001b+0x75 [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() in Microsoft.Build.dll:token 0x60015fb+0x3e [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
C:\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\6.0.0-rc.1.21371.1\Sdk\WasmApp.Native.targets(209,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) in Microsoft.Build.dll:token 0x600147a+0x2b5 [C:\Users\jcarnero\source\dotnet-wasm-sample\src\console\Wasm.Console.Sample.csproj]
                   Done executing task "PInvokeTableGenerator" -- FAILED. (TaskId:151)

This are the most relevants parts of the code:

[DllImport(DllName)]
public static extern unsafe void callCbk(delegate*<void> cbk);
typedef void (*callback)(void);

void callCbk(callback cbk)
{
    cbk();
}

And I'm using version

  Microsoft.AspNetCore.App 6.0.0-rc.1.21370.12 [C:\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.0-rc.1.21369.14 [C:\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 6.0.0-rc.1.21369.7 [C:\dotnet\shared\Microsoft.WindowsDesktop.App]
Author: emepetres
Assignees: -
Labels:

arch-wasm, area-HostModel, untriaged

Milestone: -

@vitek-karas vitek-karas added area-Interop-mono and removed area-HostModel Microsoft.NET.HostModel issues labels Jul 22, 2021
@emepetres
Copy link
Author

Just for reference, I modified the test to use "old delegates" and MonoPInvokeCallback attribute and it is working,

@vargaz
Copy link
Contributor

vargaz commented Jul 22, 2021

#43791

@ilonatommy
Copy link
Member

@akoeplinger, what is the status on this one?

@maraf
Copy link
Member

maraf commented Jun 22, 2022

It's blocked by #69273, which is scheduled for 7.0.
After the implementation I will probably enable it here.

@maraf maraf self-assigned this Jun 22, 2022
@ilonatommy ilonatommy added the blocked Issue/PR is blocked on something - see comments label Jun 22, 2022
@maraf
Copy link
Member

maraf commented Jul 21, 2022

Moving to 8.0 as the required API has moved.

@maraf maraf modified the milestones: 7.0.0, 8.0.0 Jul 21, 2022
@devshgraphicsprogramming
Copy link

devshgraphicsprogramming commented Jul 21, 2022

Just for reference, I modified the test to use "old delegates" and MonoPInvokeCallback attribute and it is working,

@emepetres can you give an example of what one actually needs to do? I'm a novice C# programmer.

@emepetres
Copy link
Author

emepetres commented Aug 9, 2022

@devshgraphicsprogramming

Its a small world of dependencies, this essentially renders SWIG's Cross Language Polymorphism (Directors) feature unusable:
swig/swig#1262

Which we really need because C++ interfaces with JS (embind) bindings from which C# inherits is how we're working around:
dotnet/aspnetcore#44088

@maraf maraf removed the blocked Issue/PR is blocked on something - see comments label Feb 17, 2023
@maraf
Copy link
Member

maraf commented Feb 23, 2023

Still blocked until we can update System.Reflection.Metadata in the WasmAppBuilder. Once the API is available, the rest of the pipeline works.

@maraf maraf added the blocked Issue/PR is blocked on something - see comments label Feb 23, 2023
@akoeplinger akoeplinger removed their assignment Mar 8, 2023
@maraf maraf modified the milestones: 8.0.0, Future Jul 12, 2023
@maraf
Copy link
Member

maraf commented Oct 30, 2023

An alternative would be to rewrite manage to native generator to use System.Reflection.Metadata API instead of System.Reflection.MetadataLoadContext

@agocke agocke added this to AppModel Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-wasm WebAssembly architecture area-Build-mono area-Interop-mono blocked Issue/PR is blocked on something - see comments
Projects
Status: No status
Development

No branches or pull requests

8 participants