diff --git a/src/mono/mono/metadata/marshal-shared.c b/src/mono/mono/metadata/marshal-shared.c index 508b823d6324fe..75d95a799ef817 100644 --- a/src/mono/mono/metadata/marshal-shared.c +++ b/src/mono/mono/metadata/marshal-shared.c @@ -1225,6 +1225,11 @@ mono_marshal_shared_emit_object_to_ptr_conv (MonoMethodBuilder *mb, MonoType *ty mono_mb_emit_byte (mb, CEE_STIND_I); break; } + case MONO_MARSHAL_CONV_OBJECT_IUNKNOWN: { + char *msg = g_strdup_printf ("Marshaling not supported for COM type MONO_MARSHAL_CONV_OBJECT_IUNKNOWN."); + mono_marshal_shared_mb_emit_exception_marshal_directive (mb, msg); + break; + } default: { g_error ("marshalling conversion %d not implemented", conv); diff --git a/src/mono/wasm/Wasm.Build.Tests/PInvokeTableGeneratorTests.cs b/src/mono/wasm/Wasm.Build.Tests/PInvokeTableGeneratorTests.cs index 0daa8d0984920e..eb0959fcdb6425 100644 --- a/src/mono/wasm/Wasm.Build.Tests/PInvokeTableGeneratorTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/PInvokeTableGeneratorTests.cs @@ -719,6 +719,44 @@ void GenerateSourceFiles(string outputPath, int baseArg) return (buildArgs, output); } + private void EnsureComInteropCompiles(BuildArgs buildArgs, RunHost host, string id) + { + string programText = @" + using System; + using System.Runtime.CompilerServices; + using System.Runtime.InteropServices; + using System.Runtime.InteropServices.ComTypes; + + public class Test + { + public static int Main(string[] args) + { + var s = new STGMEDIUM(); + ReleaseStgMedium(ref s); + return 42; + } + + [DllImport(""ole32.dll"")] + internal static extern void ReleaseStgMedium(ref STGMEDIUM medium); + } + + "; + + buildArgs = ExpandBuildArgs(buildArgs); + + (string libraryDir, string output) = BuildProject(buildArgs, + id: id, + new BuildProjectOptions( + InitProject: () => + { + File.WriteAllText(Path.Combine(_projectDir!, "Program.cs"), programText); + }, + Publish: buildArgs.AOT, + DotnetWasmFromRuntimePack: true)); + + Assert.Contains("Generated app bundle at " + libraryDir, output); + } + private void EnsureWasmAbiRulesAreFollowed(BuildArgs buildArgs, RunHost host, string id) { string programText = @" @@ -885,6 +923,11 @@ public void EnsureWasmAbiRulesAreFollowedInAOT(BuildArgs buildArgs, RunHost host public void EnsureWasmAbiRulesAreFollowedInInterpreter(BuildArgs buildArgs, RunHost host, string id) => EnsureWasmAbiRulesAreFollowed(buildArgs, host, id); + [Theory] + [BuildAndRun(host: RunHost.Chrome, aot: true)] + public void EnsureComInteropCompilesInAOT(BuildArgs buildArgs, RunHost host, string id) => + EnsureComInteropCompiles(buildArgs, host, id); + [Theory] [BuildAndRun(host: RunHost.Chrome, aot: false)] public void UCOWithSpecialCharacters(BuildArgs buildArgs, RunHost host, string id) diff --git a/src/mono/wasm/Wasm.Build.Tests/README.md b/src/mono/wasm/Wasm.Build.Tests/README.md index 5e334d0985c9e9..19fcaa84cf3c3a 100644 --- a/src/mono/wasm/Wasm.Build.Tests/README.md +++ b/src/mono/wasm/Wasm.Build.Tests/README.md @@ -14,7 +14,7 @@ being generated. - Running: -Linux/macOS: `$ make -C src/mono/wasm run-build-tests` +Linux/macOS: `$ make -C src/mono/(browser|wasi) run-build-tests` Windows: `.\dotnet.cmd build .\src\mono\wasm\Wasm.Build.Tests\Wasm.Build.Tests.csproj -c Release -t:Test -p:TargetOS=browser -p:TargetArchitecture=wasm` - Specific tests can be run via `XUnitClassName`, and `XUnitMethodName`