question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Running my trimmed WPF .NET 5.0 application results in exception code 0xe0434352

See original GitHub issue

Problem

I saw a lot of other issues where people seem to have issues with running a WPF app with PublishTrimmed=true.

For most of the issues the fix was to add the following item group to the .csproj file:

  <ItemGroup>
    <TrimmerRootAssembly Include="System.Collections" />
    <TrimmerRootAssembly Include="System.Runtime" />
    <TrimmerRootAssembly Include="System.Runtime.Extensions" />
    <TrimmerRootAssembly Include="System.Runtime.InteropServices" />
    <TrimmerRootAssembly Include="System.Runtime.CompilerServices.VisualC" />
  </ItemGroup>

For my project however this doesn’t seem to work. When I start my .exe file nothing happens, the only thing I see is an exception in the windows event log:

Faulting application name: DeveImageOptimizerWPF.exe, version: 1.0.523.0, time stamp: 0x605138bc
Faulting module name: KERNELBASE.dll, version: 10.0.19041.964, time stamp: 0x812662a7
Exception code: 0xe0434352
Fault offset: 0x0000000000034b89
Faulting process id: 0x4b0c
Faulting application start time: 0x01d73eed93cbf116
Faulting application path: C:\Users\******\Downloads\DeveImageOptimizerWPF_win-x64_trimmed\DeveImageOptimizerWPF.exe
Faulting module path: C:\WINDOWS\System32\KERNELBASE.dll
Report Id: 27f3e7c5-9bec-47cc-9b0d-e86f9991dfbc
Faulting package full name: 
Faulting package-relative application ID: 

My application

My build command:

dotnet publish .\DeveImageOptimizerWPF\DeveImageOptimizerWPF.csproj -r win-x64 -c Release -o "DeveImageOptimizerWPF\bin\Release\net5.0-windows\win-x64\publishtrimmed\" /p:PublishSingleFile=true /p:SelfContained=true /p:IncludeNativeLibrariesForSelfExtract=true /p:PublishTrimmed=true

See also: https://github.com/devedse/DeveImageOptimizerWPF/blob/master/.github/workflows/githubactionsbuilds.yml

Build artifacts:

(If you download the trimmed .exe file the error can easily be reproduced) https://github.com/devedse/DeveImageOptimizerWPF/actions/runs/803276315#artifacts

csproj:

https://github.com/devedse/DeveImageOptimizerWPF/blob/master/DeveImageOptimizerWPF/DeveImageOptimizerWPF.csproj

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ryalanmscommented, Sep 2, 2021

Trimming is not supported by WPF. There is now an error during compilation in .NET 6.0 when Trimming is enabled for WPF.

1reaction
ThomasGoulet73commented, May 10, 2021

It was an intentional breaking change in the WindowsDesktop Sdk (WPF and WinForms). Starting with .Net 5 the Sdk will override the OutputType for WinExe. Which means that even if you set OutputType to Exe, it’ll end up being WinExe. You can override OutputType using the DisableWinExeOutputInference property:

<PropertyGroup>
  <OutputType>Exe</OutputType>
  <DisableWinExeOutputInference>true</DisableWinExeOutputInference>
</PropertyGroup>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Running my trimmed WPF .NET 5.0 application results in ...
NET 5.0 application results in exception code 0xe0434352 #4485 ... seem to have issues with running a WPF app with PublishTrimmed=true.
Read more >
How do I fix a .NET windows application crashing at startup ...
When running a command line application it would immediately exit, and I saw this exception in the Event Viewer but received no other...
Read more >
WPF .NET application breaks with error Could not load file ...
I have a C# WPF .NET application that uses a 3rd party SDK called PaymentSDK.dll which I include and reference inside the application...
Read more >
ArcGIS Runtime WPF application crashes when kept i...
Hi All, We have a WPF windows application developed using ArcGIS Runtime. ... NET Framework 4.6.1-WPF ... Exception code: 0xe0434352.
Read more >
Creating and Publishing WPF and WinForm Apps in .NET Core
NET Framework WPF application for comparison to see what has changed. ... Source Code Download: https://leadmagnets. app /?
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found