Publishing single file WPF application breaks if app.config is used
See original GitHub issueIf 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:
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishSingleFile>true</PublishSingleFile>
<PublishReadyToRun>true</PublishReadyToRun>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<DebugType>none</DebugType>
<DebugSymbols>false</DebugSymbols>
</PropertyGroup>
And when publishing the project with dotnet publish -c Release
, then the output looks good:
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
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:7 (3 by maintainers)
Top Results From Across the Web
publish the C# project with configuration file
Then go to Project -> Properties -> Publish , click on Application Files... and make sure, that Publish Status and Download Group for...
Read more >How To Publish a Single File .NET Application - YouTube
Comments52 · Publishing /Deploying WPF Applications (feat. · Publishing - WPF MVVM TUTORIAL #10 · How to Create Setup .exe in Visual Studio...
Read more >Redirecting Assembly Versions - .NET Framework
You can redirect your app to use a different version of an assembly in a number of ways: through publisher policy, through an...
Read more >Essential .NET 6 app settings tips... master developer and ...
In this tutorial, you will learn how to configure a .NET 6 application to work with either environment-specific settings, or, ...
Read more >Publishing A Single EXE File In .NET Core 3.0
Pretty self explanatory : Publish the project from the current directory; Build the project to run on Windows 64 bit machines; Build in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Adding IDC WPF: @vishalmsft @singhashish-wpf …
having the same problem here, once I publish with PublishSingleFile set to true, I can’t read(or write) the setting from app.dll.config. Note that everything works fine if I publish with PublishSingleFile set to false.