dotnet / dotnet/wpf

Empty WPF app crashes when published as a self-contained single file on .NET 11 Preview 7

Open
#11,842 0 comments 0 reactions 0 assignees View on GitHub
area-NetSDK Bug Cost:M Priority:1 regression
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

### Description

A new empty WPF application targeting .NET 11 crashes on startup when published as a self-contained single-file application.

The failure occurs both with and without `IncludeNativeLibrariesForSelfExtract=true`. Ordinary non-single-file self-contained publishing works correctly.

This appears related to:

- https://github.com/dotnet/wpf/pull/11575
- https://github.com/dotnet/wpf/issues/11651
- https://github.com/dotnet/wpf/pull/11664

PR #11575 changed `DirectWriteForwarder.dll` and `System.Printing.dll` from pure MSIL to IJW mixed-mode assemblies. PR #11664 fixed ordinary self-contained publishing by packaging `ijwhost.dll` as a native runtime asset, but single-file publishing still bundles `DirectWriteForwarder.dll` and it fails during startup.

### Reproduction Steps

Using .NET SDK `11.0.100-preview.7.26381.103`:

```powershell
dotnet new wpf -n WpfSingleFileRepro -f net11.0
cd WpfSingleFileRepro

dotnet publish -c Release -r win-x64 --self-contained true `
-p:PublishSingleFile=true `
-p:IncludeNativeLibrariesForSelfExtract=true `
-o .\publish-single

.\publish-single\WpfSingleFileRepro.exe
```

### Expected behavior

The empty WPF application should start and display its window.

### Actual behavior

The process terminates during `System.Windows.Application` initialization with exit code `0xE0434352`:

```text
Unhandled exception. System.TypeInitializationException:
The type initializer for 'System.Windows.Application' threw an exception.

---> System.TypeInitializationException:
The type initializer for '' threw an exception.

---> System.BadImageFormatException:
File name: '...\publish-single\DirectWriteForwarder.dll'

at System.Windows.Application.ApplicationInit()
at System.Windows.Application..ctor()
at WpfSingleFileRepro.App.Main()
```

### Regression?

_No response_

### Known Workarounds

_No response_

### Impact

_No response_

### Configuration

SDK: 11.0.100-preview.7.26381.103
Runtime: 11.0.0-preview.7.26381.103
MSBuild: 18.10.0-1.26381.103
OS: Windows 11, build 10.0.26200

### Other information

_No response_

Contributor guide

Open the contributing guide

Research direction

Reproduce the failure with the documented .NET SDK, WPF template, and single-file publish commands, then read PRs #11575 and #11664 plus issue #11651 for the mixed-mode assembly packaging changes. Done means the published empty WPF application starts and displays its window without the DirectWriteForwarder.dll BadImageFormatException.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
build-system, desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.