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.

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

See original GitHub issue

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:

<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: image 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:open
  • Created 3 years ago
  • Reactions:2
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
ryalanmscommented, Nov 15, 2021

Adding IDC WPF: @vishalmsft @singhashish-wpf

0reactions
IJlimacommented, Apr 6, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

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