[WASM] MarshalingPInvokeScanner fails when using a nested value type contained in a different assembly.

Open
#110,938 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
csharp, wasm
Domain
build-system

Research direction

Build the attached dotnet_wasm_issue.zip reproduction using the wasmconsole template, then inspect MarshalingPInvokeScanner and MinimalMarshalingTypeCompatibilityProvider.cs around line 142. Compare the nested value type case with the documented top-level-type workaround; done means the Wasm project builds and runs successfully without the MSB4018 or NotImplementedException error.

Written by the indexing model from the issue text.

Description

arch-wasm area-Interop-mono
Description

In a WASM project, when using NativeFileReference for linking, it seems that the types used in DllImport are being scanned.
However, this process does not appear to support nested types contained in other assemblies.

It seems like the issue stems from the assumption that the parent of the type is always an AssemblyReference.
https://github.com/dotnet/runtime/blob/main/src/tasks/MonoTargetsTasks/MarshalingPInvokeScanner/MinimalMarshalingTypeCompatibilityProvider.cs#L142

Reproduction Steps

Download the zip file and try building the WasmProject.
dotnet_wasm_issue.zip

This project uses the wasmconsole template as the minimal setup to reproduce the issue, but the same problem occurs in Blazor WebAssembly as well.

Expected behavior

The project should build and run successfully.

Actual behavior

Error occurs.

C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\8.0.11\Sdk\WasmAp
p.Native.targets(737,5): error MSB4018: "MarshalingPInvokeScanner" タスクが予期せずに 失敗しました。

C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\8.0.11\Sdk\WasmAp
p.Native.targets(737,5): error MSB4018: System.NotImplementedException: Unsupported R
esolutionScope kind 'TypeReference' used in type :InnerValueType.

Regression?

No response

Known Workarounds

There is no issue when using top-level types, even if they are contained in a different assembly.

Configuration

No response

Other information

No response

Dominant language
C#
Stars
18.3k
Forks
5.6k
PR merge metrics
PR metrics pending

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/runtime

All issues in dotnet/runtime

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.