How to prevent "app.config" error after porting to .Net Core an app with an app.config and a .settings file?

Viewed 1072

I've run into an issue while porting some of our .Net Framework projects to .Net Core. After porting, if the project has an "app.config" AND a "Settings.settings" file I get an error every time that I open the project or view the project properties.

After some investigation, I've managed to reproduce the problem without porting - just by creating a .Net Core Windows Forms app and then adding an app.config and a settings.settings as follows:

Using Visual Studio 2019 version 16.7.3 (error also occurs with older versions):

  1. Create a new "Windows Forms App (.Net Core)" .Net Core 3.1 project.
  2. In the IDE, right-click the project in Solution Explorer and select Add | New Item...
  3. Select "Application Configuration File" and click 'Add'.
  4. Go to "Project Properties" and the "Settings" tab.
  5. Click "This project does not contain a default settings file. Click here to create one."
  6. Add a string user setting called "Setting" with a value of "test".
  7. Build application.
  8. Close all the project windows.
  9. Go to "Project Properties" and the "Settings" tab.

At this point I see an error:

An error occurred while reading the app.config file. The file might be corrupted or contain invalid XML.

This error is now displayed every time I open the project or go to the project properties.

How can I prevent this error from occuring, other than by deleting "App.Config"?

Note that despite the error, the settings do work correctly - they can be read and written at runtime. It's just an irritating and slightly worrying error message that I'd like to see gone!


[EDIT] I submitted this to Microsoft as a bug here: https://github.com/dotnet/sdk/issues/13478

0 Answers
Related