diff --git a/src/mono/mono/component/marshal-ilgen-stub.c b/src/mono/mono/component/marshal-ilgen-stub.c index 277261c6b6dde5..d6d0fdd960de32 100644 --- a/src/mono/mono/component/marshal-ilgen-stub.c +++ b/src/mono/mono/component/marshal-ilgen-stub.c @@ -43,11 +43,15 @@ stub_emit_marshal_ilgen (EmitMarshalContext* m, int argnum, MonoType* t, case MONO_TYPE_U8: case MONO_TYPE_FNPTR: return lightweight_cb->emit_marshal_scalar (m, argnum, t, spec, conv_arg, conv_arg_type, action); - default: + default: { + if (m_class_is_enumtype (m_type_data_get_klass_unchecked (t))) + return lightweight_cb->emit_marshal_scalar (m, argnum, t, spec, conv_arg, conv_arg_type, action); + emit_throw_exception (lightweight_cb, m->mb, "System", "ApplicationException", g_strdup("Cannot marshal nonblittlable types without marshal-ilgen.")); break; } + } return 0; } diff --git a/src/mono/wasm/Wasm.Build.Tests/NativeBuildTests.cs b/src/mono/wasm/Wasm.Build.Tests/NativeBuildTests.cs index 87b6c0cf0929ec..6716d4d350a298 100644 --- a/src/mono/wasm/Wasm.Build.Tests/NativeBuildTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/NativeBuildTests.cs @@ -102,5 +102,18 @@ public void NativeBuildIsRequired(Configuration config, bool aot) (string _, string output) = PublishProject(info, config, new PublishOptions(ExpectSuccess: false, AOT: aot)); Assert.Contains("WasmBuildNative is required", output); } + + [Fact] + public async Task ZipArchiveInteropTest() + { + Configuration config = Configuration.Debug; + ProjectInfo info = CopyTestAsset(config, false, TestAsset.WasmBasicTestApp, "ZipArchiveInteropTest", extraProperties: "true"); + BuildProject(info, config, new BuildOptions(AssertAppBundle: false)); + RunResult result = await RunForBuildWithDotnetRun(new BrowserRunOptions(config, TestScenario: "ZipArchiveInteropTest")); + Assert.Collection( + result.TestOutput, + m => Assert.Equal("Zip file created successfully.", m) + ); + } } } diff --git a/src/mono/wasm/testassets/WasmBasicTestApp/App/ZipArchiveInteropTest.cs b/src/mono/wasm/testassets/WasmBasicTestApp/App/ZipArchiveInteropTest.cs new file mode 100644 index 00000000000000..d7ba8014cd7135 --- /dev/null +++ b/src/mono/wasm/testassets/WasmBasicTestApp/App/ZipArchiveInteropTest.cs @@ -0,0 +1,29 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.IO; +using System.IO.Compression; +using System.Globalization; +using System.Threading.Tasks; +using System.Resources; +using System.Runtime.InteropServices.JavaScript; +using System.Text; + +public partial class ZipArchiveInteropTest +{ + [JSExport] + public static async Task Run() + { + using var zipFileStream = new MemoryStream(); + using var zipArchive = new ZipArchive(zipFileStream, ZipArchiveMode.Create); + + var entry = zipArchive.CreateEntry("sample.txt"); + using (var entryStream = entry.Open()) + { + await entryStream.WriteAsync(Encoding.UTF8.GetBytes("Sample text content")); + } + + TestOutput.WriteLine("Zip file created successfully."); + } +} diff --git a/src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/main.js b/src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/main.js index 90595ef290f8e3..7a9d1ebc4a5ad7 100644 --- a/src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/main.js +++ b/src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/main.js @@ -223,6 +223,10 @@ try { case "LibraryInitializerTest": exit(0); break; + case "ZipArchiveInteropTest": + exports.ZipArchiveInteropTest.Run(); + exit(0); + break; case "AppSettingsTest": exports.AppSettingsTest.Run(); exit(0);