Skip to content
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

ConvertDllsToWebCil fails ugly for invalid assembly #101154

Open
danmoseley opened this issue Apr 17, 2024 · 10 comments · May be fixed by #101162
Open

ConvertDllsToWebCil fails ugly for invalid assembly #101154

danmoseley opened this issue Apr 17, 2024 · 10 comments · May be fixed by #101162
Assignees
Labels
arch-wasm WebAssembly architecture area-Build-mono os-browser Browser variant of arch-wasm
Milestone

Comments

@danmoseley
Copy link
Member

danmoseley commented Apr 17, 2024

Somewhere in this stack it should catch BadImageFormatException and Log.ErrorFromException(..) then return false from the task.
I assume the repro is to feed the task an empty file, or similar.
version: 8.0.4

just after

2024-04-17T00:49:58.7245127Z   Optimizing assemblies for size may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink
2024-04-17T00:49:58.7274180Z   Optimizing assemblies for size. This process might take a while.

I get

.../.nuget/packages/microsoft.net.sdk.webassembly.pack/8.0.4/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets(452,5): error MSB4018: The "ConvertDllsToWebCil" task failed unexpectedly. [/home/runner/work/aspire-samples/aspire-samples/samples/Metrics/MetricsApp.Client/MetricsApp.Client.csproj]
.../.nuget/packages/microsoft.net.sdk.webassembly.pack/8.0.4/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets(452,5): error MSB4018: System.BadImageFormatException: Image is too small. [/home/runner/work/aspire-samples/aspire-samples/samples/Metrics/MetricsApp.Client/MetricsApp.Client.csproj]
.../.nuget/packages/microsoft.net.sdk.webassembly.pack/8.0.4/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets(452,5): error MSB4018:    at System.Reflection.Throw.ImageTooSmall() [/home/runner/work/aspire-samples/aspire-samples/samples/Metrics/MetricsApp.Client/MetricsApp.Client.csproj]
.../.nuget/packages/microsoft.net.sdk.webassembly.pack/8.0.4/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets(452,5): error MSB4018:    at System.Reflection.PortableExecutable.PEHeaders..ctor(Stream peStream, Int32 size, Boolean isLoadedImage) [/home/runner/work/aspire-samples/aspire-samples/samples/Metrics/MetricsApp.Client/MetricsApp.Client.csproj]
.../.nuget/packages/microsoft.net.sdk.webassembly.pack/8.0.4/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets(452,5): error MSB4018:    at System.Reflection.PortableExecutable.PEReader.InitializePEHeaders() [/home/runner/work/aspire-samples/aspire-samples/samples/Metrics/MetricsApp.Client/MetricsApp.Client.csproj]
.../.nuget/packages/microsoft.net.sdk.webassembly.pack/8.0.4/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets(452,5): error MSB4018:    at System.Reflection.PortableExecutable.PEReader.get_PEHeaders() [/home/runner/work/aspire-samples/aspire-samples/samples/Metrics/MetricsApp.Client/MetricsApp.Client.csproj]
.../.nuget/packages/microsoft.net.sdk.webassembly.pack/8.0.4/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets(452,5): error MSB4018:    at Microsoft.NET.WebAssembly.Webcil.WebcilConverter.GatherInfo(PEReader peReader, WCFileInfo& wcInfo, PEFileInfo& peInfo) [/home/runner/work/aspire-samples/aspire-samples/samples/Metrics/MetricsApp.Client/MetricsApp.Client.csproj]
.../.nuget/packages/microsoft.net.sdk.webassembly.pack/8.0.4/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets(452,5): error MSB4018:    at Microsoft.NET.WebAssembly.Webcil.WebcilConverter.ConvertToWebcil() [/home/runner/work/aspire-samples/aspire-samples/samples/Metrics/MetricsApp.Client/MetricsApp.Client.csproj]
.../.nuget/packages/microsoft.net.sdk.webassembly.pack/8.0.4/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets(452,5): error MSB4018:    at Microsoft.WebAssembly.Build.Tasks.WebcilConverter.ConvertToWebcil() [/home/runner/work/aspire-samples/aspire-samples/samples/Metrics/MetricsApp.Client/MetricsApp.Client.csproj]
.../.nuget/packages/microsoft.net.sdk.webassembly.pack/8.0.4/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets(452,5): error MSB4018:    at Microsoft.NET.Sdk.WebAssembly.ConvertDllsToWebCil.Execute() [/home/runner/work/aspire-samples/aspire-samples/samples/Metrics/MetricsApp.Client/MetricsApp.Client.csproj]
.../.nuget/packages/microsoft.net.sdk.webassembly.pack/8.0.4/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets(452,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [/home/runner/work/aspire-samples/aspire-samples/samples/Metrics/MetricsApp.Client/MetricsApp.Client.csproj]
.../.nuget/packages/microsoft.net.sdk.webassembly.pack/8.0.4/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets(452,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [/home/runner/work/aspire-samples/aspire-samples/samples/Metrics/MetricsApp.Client/MetricsApp.Client.csproj]

https://productionresultssa13.blob.core.windows.net/actions-results/5604d4bc-a8b0-4df9-99a1-482f4b6ac748/workflow-job-run-1d849a45-2f30-5fbb-3226-b730a17a93af/logs/job/job-logs.txt?rsct=text%2Fplain&se=2024-04-17T01%3A10%3A19Z&sig=o0tEe09NJLnPaaMWW9u67PdcAsaTGDKrNhyowktpPiE%3D&sp=r&spr=https&sr=b&st=2024-04-17T01%3A00%3A14Z&sv=2021-12-02

I don't know where the bug is leading to this, perhaps the trimming is producing an empty file, but that's a separate issue.

@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Apr 17, 2024
@lewing lewing added this to the 9.0.0 milestone Apr 17, 2024
@lewing lewing added arch-wasm WebAssembly architecture os-browser Browser variant of arch-wasm and removed untriaged New issue has not been triaged by the area owner labels Apr 17, 2024
@sebastienros
Copy link
Member

Same thing is happening in aspire-samples here: https://github.com/dotnet/aspire-samples/actions/runs/8680403862/job/23941003242#step:6:245

@lewing
Copy link
Member

lewing commented Apr 17, 2024

@sbomer any idea why the trimmer have started producing empty or invalid assemblies recently?

@danmoseley
Copy link
Member Author

danmoseley commented Apr 17, 2024

I opened this to track the bad error message. If the trimmer is producing an empty file because of a bug rather than something wierd in the aspire-samples build (and this may well be the case, IDK) that would be a separate bug.

It keeps happening there, though eg https://github.com/dotnet/aspire-samples/actions/runs/8725954534/job/23940133588?pr=209 sometimes Windows sometimes Linux.

@sbomer
Copy link
Member

sbomer commented Apr 17, 2024

@sbomer any idea why the trimmer have started producing empty or invalid assemblies recently?

No. We recently changed some of the PE headers in #101038, but I don't see how that would lead to this crash, and especially not nondeterministically.

Can we confirm which file is being passed to ConvertDllsToWebCil that is causing the failure?

@DamianEdwards
Copy link
Member

As @sebastienros points out, this is happening quite a lot in the CI for dotnet/aspire-samples, specifically on this project: https://github.com/dotnet/aspire-samples/tree/996dd5e7909ef60a561e6372ad40559441f66b91/samples/Metrics/MetricsApp.Client

@maraf
Copy link
Member

maraf commented Apr 19, 2024

A workaround for the time being is to set WasmEnableWebcil=false

@maraf
Copy link
Member

maraf commented Apr 19, 2024

Could it be a some kind of race condition from running the publish in parallel?

https://github.com/dotnet/aspire-samples/blob/main/build/Build.proj#L29

@sebastienros
Copy link
Member

@maraf I created this PR to disable it dotnet/aspire-samples#214 but this does the same thing.

@maraf
Copy link
Member

maraf commented Apr 19, 2024

I believe this inner parallel double publish dotnet/aspire-samples#214 (comment) is also the root case of this issue with empty trimmed dlls

EDIT: Confirmed, the ConvertDllsToWebCil is running in both parallel publishes for the same project.

@javiercn
Copy link
Member

@maraf just in case its due to some of the workarounds I had to add for my work, I've created a PR that removes them dotnet/sdk#39689

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 os-browser Browser variant of arch-wasm
Projects
None yet
7 participants