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