dotnet / dotnet/wpf

Publishing single file WPF application breaks if app.config is used

Open
#3,875 7 comments 3 reactions 0 assignees View on GitHub
Bug Investigate
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

If you publish a WPF application in .NET 5, and this application is using an App.config, the application crashes when the framework is trying to find this file, even though the file is part of the published output.
The following settings are configured in project:
```

win-x64
true
true
true
true
none
false

```
And when publishing the project with `dotnet publish -c Release`, then the output looks good:
![image](https://user-images.githubusercontent.com/26246346/100893197-61d7e680-34bb-11eb-9902-2fda4824b070.png)
Correct name of the config file is there.

However, when the app is trying to access any setting in this file with ConfigurationManager, the app crashes:

```
Application: WpfNet5App.exe
CoreCLR Version: 5.0.20.51904
.NET Version: 5.0.0
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.FileNotFoundException: The system cannot find the file specified. (0x80070002)
at System.Reflection.RuntimeModule.GetFullyQualifiedName()
at System.Reflection.RuntimeModule.get_Name()
at System.Configuration.ClientConfigPaths..ctor(String exePath, Boolean includeUserConfig)
at System.Configuration.ClientConfigPaths.GetPaths(String exePath, Boolean includeUserConfig)
at System.Configuration.Internal.ConfigurationManagerInternal.System.Configuration.Internal.IConfigurationManagerInternal.get_ExeProductName()
at System.Configuration.ApplicationSettingsBase.get_Initializer()
at System.Configuration.ApplicationSettingsBase.CreateSetting(PropertyInfo propertyInfo)
at System.Configuration.ApplicationSettingsBase.EnsureInitialized()
at System.Configuration.ApplicationSettingsBase.get_Properties()
at System.Configuration.SettingsBase.GetPropertyValueByName(String propertyName)
at System.Configuration.SettingsBase.get_Item(String propertyName)
at System.Configuration.ApplicationSettingsBase.GetPropertyValue(String propertyName)
at System.Configuration.ApplicationSettingsBase.get_Item(String propertyName)
at WpfNet5App.Properties.Settings.get_HelloMessage()
at WpfNet5App.MainWindow.Button_Click(Object sender, RoutedEventArgs e)
```

Attaching the super-simple example.
[WpfNet5App.zip](https://github.com/dotnet/core/files/5630310/WpfNet5App.zip)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.