dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.26k stars 4.73k forks source link

Blazor WASM AoTing ClosedXML/DocumentFormat.OpenXml fails #69898

Closed georg-jung closed 2 years ago

georg-jung commented 2 years ago

Description

I'm building a Blazor WASM app that should support export of data to the xlsx format. I chose ClosedXML as a library for xlsx production. My non-AoTed builds run fine in the browser. To achieve a production-ready runtime performance, I want to AoT my code prior to deploying it. ClosedXML depends on the Microsoft-maintained DocumentFormat.OpenXml library. I first tried AoTing my project with the .Net 6 SDK, which fails fast. After reading @radical's comment here I decided to give the current .Net 7 preview (4) a try instead. AoTing the assembly still fails on .Net 7. It takes quite some time before failing and produces more meaningful error messages though.

Side node: While trimming the assembly does work, it takes more than half an hour to complete.

/cc @radical

Reproduction Steps

AoT a blazor wasm project which uses ClosedXML, either using .Net 6 or using .Net 7 preview 4. See a relevant build log. Running this workflow with AoT enabled reproducibly fails. Executing the same docker build locally fails too.

Expected behavior

Actual behavior

AoTing ClosedXML and/or it's dependency DocumentFormat.OpenXml on .Net 7 preview 4 fails.

#20 3542.5 /usr/share/dotnet/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/7.0.0-preview.4.22229.4/Sdk/WasmApp.Native.targets(292,5): warning : Failed to generate icall function for method '[System.Private.CoreLib] System.Enum::InternalHasFlag' because type 'System.Enum' is not supported for parameter named 'flags'. Ignoring. [/src/src/AV.AvA.BlazorWasmClient/AV.AvA.BlazorWasmClient.csproj]
ype 'System.RuntimeType' is not supported for parameter named ''. Ignoring. [/src/src/AV.AvA.BlazorWasmClient/AV.AvA.BlazorWasmClient.csproj]
#20 3542.7 /usr/share/dotnet/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/7.0.0-preview.4.22229.4/Sdk/WasmApp.Native.targets(292,5): warning : Failed to generate icall function for method '[System.Private.CoreLib] System.Reflection.AssemblyName::get_public_token' because type 'System.Byte' is not supported for parameter named ''. Ignoring. [/src/src/AV.AvA.BlazorWasmClient/AV.AvA.BlazorWasmClient.csproj]
#20 3542.7 /usr/share/dotnet/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/7.0.0-preview.4.22229.4/Sdk/WasmApp.Native.targets(292,5): warning : Failed to generate icall function for method '[System.Private.CoreLib] System.Reflection.AssemblyName::ParseAssemblyName' because type 'Mono.MonoAssemblyName' is not supported for parameter named ''. Ignoring. [/src/src/AV.AvA.BlazorWasmClient/AV.AvA.BlazorWasmClient.csproj]
#20 3542.7 /usr/share/dotnet/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/7.0.0-preview.4.22229.4/Sdk/WasmApp.Native.targets(292,5): warning : Failed to generate icall function for method '[System.Private.CoreLib] System.Reflection.RuntimeAssembly::get_code_base' because type 'System.Reflection.Assembly' is not supported for parameter named ''. Ignoring. [/src/src/AV.AvA.BlazorWasmClient/AV.AvA.BlazorWasmClient.csproj]
#20 3542.7 /usr/share/dotnet/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/7.0.0-preview.4.22229.4/Sdk/WasmApp.Native.targets(292,5): warning : Failed to generate icall function for method '[System.Private.CoreLib] System.Reflection.RuntimeAssembly::get_fullname' because type 'System.Reflection.Assembly' is not supported for parameter named ''. Ignoring. [/src/src/AV.AvA.BlazorWasmClient/AV.AvA.BlazorWasmClient.csproj]
#20 3542.8 /usr/share/dotnet/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/7.0.0-preview.4.22229.4/Sdk/WasmApp.Native.targets(472,5): error : unable to find python in $PATH [/src/src/AV.AvA.BlazorWasmClient/AV.AvA.BlazorWasmClient.csproj]
#20 3542.8 /usr/share/dotnet/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/7.0.0-preview.4.22229.4/Sdk/WasmApp.Native.targets(472,5): error MSB3073: The command "emcc --version" exited with code 1. [/src/src/AV.AvA.BlazorWasmClient/AV.AvA.BlazorWasmClient.csproj]

Regression?

Does not work using .Net 6 SDK or .Net 7 Preview 4 SDK. Everything does work if AoT is disabled.

Known Workarounds

No response

Configuration

No response

Other information

No response

radical commented 2 years ago

error : unable to find python in $PATH - You need python (try 3.6+) installed.

ghost commented 2 years ago

This issue has been marked needs-author-action and may be missing some important information.

ghost commented 2 years ago

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

Issue Details
### Description I'm building a [Blazor WASM app](https://github.com/akademischerverein/ava) that should support export of data to the xlsx format. I chose [ClosedXML](https://www.nuget.org/packages/ClosedXML/) as a library for xlsx production. My non-AoTed builds run fine in the browser. To achieve a production-ready runtime performance, I want to AoT my code prior to deploying it. ClosedXML depends on the Microsoft-maintained [DocumentFormat.OpenXml](https://www.nuget.org/packages/DocumentFormat.OpenXml/) library. I first tried AoTing my project with the .Net 6 SDK, which [fails fast](https://github.com/akademischerverein/ava/runs/6611349769). After reading [@radical's comment here](https://github.com/dotnet/runtime/issues/61053#issuecomment-957017820) I decided to give the current .Net 7 preview (4) a try instead. AoTing the assembly still [fails on .Net 7](https://github.com/akademischerverein/ava/runs/6624763753). It takes quite some time before failing and produces more meaningful error messages though. Side node: While trimming the assembly does work, it takes more than half an hour to complete. /cc @radical ### Reproduction Steps AoT a blazor wasm project which uses ClosedXML, either using .Net 6 or using .Net 7 preview 4. See [a relevant build log](https://github.com/akademischerverein/ava/actions/runs/2396254596). Running [this workflow](https://github.com/akademischerverein/ava/actions/workflows/manual.yml) with AoT enabled reproducibly fails. Executing the same docker build locally fails too. * [.csproj](https://github.com/akademischerverein/ava/blob/aot-with-net7/src/AV.AvA.BlazorWasmClient/AV.AvA.BlazorWasmClient.csproj) * [Dockerfile](https://github.com/akademischerverein/ava/blob/master/src/AV.AvA.BlazorWasmClient/Dockerfile) * [Workflow](https://github.com/akademischerverein/ava/blob/master/.github/workflows/docker-build-and-push.yml) ### Expected behavior * User Story: I want to be able to AoT a Blazor WASM App with an Excel Export feature * Thus, I want to be able to AoT the `ClosedXML` library and its dependency `DocumentFormat.OpenXml` * It would further be great if the process does not take 1h+, but that might be a seperate issue ### Actual behavior AoTing ClosedXML and/or it's dependency DocumentFormat.OpenXml on .Net 7 preview 4 [fails](https://github.com/akademischerverein/ava/runs/6624763753). #20 3542.5 /usr/share/dotnet/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/7.0.0-preview.4.22229.4/Sdk/WasmApp.Native.targets(292,5): warning : Failed to generate icall function for method '[System.Private.CoreLib] System.Enum::InternalHasFlag' because type 'System.Enum' is not supported for parameter named 'flags'. Ignoring. [/src/src/AV.AvA.BlazorWasmClient/AV.AvA.BlazorWasmClient.csproj] ype 'System.RuntimeType' is not supported for parameter named ''. Ignoring. [/src/src/AV.AvA.BlazorWasmClient/AV.AvA.BlazorWasmClient.csproj] #20 3542.7 /usr/share/dotnet/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/7.0.0-preview.4.22229.4/Sdk/WasmApp.Native.targets(292,5): warning : Failed to generate icall function for method '[System.Private.CoreLib] System.Reflection.AssemblyName::get_public_token' because type 'System.Byte' is not supported for parameter named ''. Ignoring. [/src/src/AV.AvA.BlazorWasmClient/AV.AvA.BlazorWasmClient.csproj] #20 3542.7 /usr/share/dotnet/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/7.0.0-preview.4.22229.4/Sdk/WasmApp.Native.targets(292,5): warning : Failed to generate icall function for method '[System.Private.CoreLib] System.Reflection.AssemblyName::ParseAssemblyName' because type 'Mono.MonoAssemblyName' is not supported for parameter named ''. Ignoring. [/src/src/AV.AvA.BlazorWasmClient/AV.AvA.BlazorWasmClient.csproj] #20 3542.7 /usr/share/dotnet/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/7.0.0-preview.4.22229.4/Sdk/WasmApp.Native.targets(292,5): warning : Failed to generate icall function for method '[System.Private.CoreLib] System.Reflection.RuntimeAssembly::get_code_base' because type 'System.Reflection.Assembly' is not supported for parameter named ''. Ignoring. [/src/src/AV.AvA.BlazorWasmClient/AV.AvA.BlazorWasmClient.csproj] #20 3542.7 /usr/share/dotnet/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/7.0.0-preview.4.22229.4/Sdk/WasmApp.Native.targets(292,5): warning : Failed to generate icall function for method '[System.Private.CoreLib] System.Reflection.RuntimeAssembly::get_fullname' because type 'System.Reflection.Assembly' is not supported for parameter named ''. Ignoring. [/src/src/AV.AvA.BlazorWasmClient/AV.AvA.BlazorWasmClient.csproj] #20 3542.8 /usr/share/dotnet/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/7.0.0-preview.4.22229.4/Sdk/WasmApp.Native.targets(472,5): error : unable to find python in $PATH [/src/src/AV.AvA.BlazorWasmClient/AV.AvA.BlazorWasmClient.csproj] #20 3542.8 /usr/share/dotnet/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/7.0.0-preview.4.22229.4/Sdk/WasmApp.Native.targets(472,5): error MSB3073: The command "emcc --version" exited with code 1. [/src/src/AV.AvA.BlazorWasmClient/AV.AvA.BlazorWasmClient.csproj] ### Regression? Does not work using .Net 6 SDK or .Net 7 Preview 4 SDK. Everything does work if AoT is disabled. ### Known Workarounds _No response_ ### Configuration _No response_ ### Other information _No response_
Author: georg-jung
Assignees: -
Labels: `arch-wasm`, `area-Codegen-AOT-mono`, `needs-author-action`
Milestone: -
georg-jung commented 2 years ago

Sorry, I missed that when creating the issue and thought dotnet workload install wasm-tools would bring all relevant dependencies (might be great to issue a warning there when python is missing?). I fixed that in the meantime and will report back with my results, once my builds finish.

Is this expected to take more than 10min though?

#20 82.94   [100/102] netstandard.dll -> netstandard.dll.bc
#20 88.06   [101/102] System.Private.CoreLib.dll -> System.Private.CoreLib.dll.bc
#20 819.8   [102/102] DocumentFormat.OpenXml.dll -> DocumentFormat.OpenXml.dll.bc
#20 823.4   Compiling native assets with emcc with -Oz. This may take a while ...
#20 823.7   [1/3] pinvoke.c -> pinvoke.o [took 0.30s]
#20 823.8   [2/3] driver.c -> driver.o [took 0.38s]

There seems to be something special about DocumentFormat.OpenXml. Trimming it takes 30min+, AoTing it takes quite long too.

radical commented 2 years ago

It's in the messages that you shared:

#20 3542.8 /usr/share/dotnet/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/7.0.0-preview.4.22229.4/Sdk/WasmApp.Native.targets(472,5):
  error : unable to find python in $PATH [/src/src/AV.AvA.BlazorWasmClient/AV.AvA.BlazorWasmClient.csproj]
#20 3542.8 /usr/share/dotnet/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/7.0.0-preview.4.22229.4/Sdk/WasmApp.Native.targets(472,5):
  error MSB3073: The command "emcc --version" exited with code 1. [/src/src/AV.AvA.BlazorWasmClient/AV.AvA.BlazorWasmClient.csproj]

Yeah, AOT can take time. That particular assembly might be generics heavy.

radical commented 2 years ago

We should check that when installing the workload though.

georg-jung commented 2 years ago

In .Net 7 preview with python3 installed it does build successfully (takes ~30min). Thanks for your help! And sorry for the non-issue.

If someone facing a similar situation finds this: