Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
SWarnberg opened this issue Dec 2, 2020 · 7 comments
Open
Labels
Bug Product bug (most likely) Investigate Requires further investigation by the WPF team.

Comments

@SWarnberg
Copy link

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

@mairaw mairaw transferred this issue from dotnet/core Dec 2, 2020
@lindexi
Copy link
Member

lindexi commented Dec 3, 2020

Duplicate of #3516 #3634?

@ryalanms ryalanms added the Bug Product bug (most likely) label Dec 3, 2020
@ryalanms ryalanms added this to the 6.0.0 milestone Dec 3, 2020
@SWarnberg
Copy link
Author

Milestone 6, really? Then I think you need to go public and announce that single-file deployment isn't supported in WPF for .NET 5.

@ryalanms ryalanms added the Investigate Requires further investigation by the WPF team. label Dec 4, 2020
@ryalanms ryalanms modified the milestones: 6.0.0, .NET 5.0 Servicing Dec 4, 2020
@ryalanms
Copy link
Member

ryalanms commented Dec 9, 2020

@SamBent noticed that the configuration file has the wrong name, which should end in .exe.config, not .dll.config. Renaming the file in the publish directory should fix the crash. The WPF team is investigating a proper fix. Thanks.

@SWarnberg
Copy link
Author

@SamBent noticed that the configuration file has the wrong name, which should end in .exe.config, not .dll.config. Renaming the file in the publish directory should fix the crash. The WPF team is investigating a proper fix. Thanks.

No, it actually doesn't help to rename the file. Tried that before publishing this bug. You see when you publish or build w/o single file, the file name is still *.dll.config, and it works with that name.

@rajeshaz09
Copy link

@ryalanms any news on this?

@ryalanms
Copy link
Member

Adding IDC WPF: @vishalmsft @singhashish-wpf ...

@IJlima
Copy link

IJlima commented 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.

@karelz karelz removed this from the .NET 5.0 Servicing milestone Sep 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Product bug (most likely) Investigate Requires further investigation by the WPF team.
Projects
None yet
Development

No branches or pull requests

6 participants