SettingsPropertyNotFoundException when saving a property after publishing application

Rafał Klinowski 1 Reputation point
2021-03-03T15:18:51.3+00:00

I am working on a WPF app.I have created the Properties.Settings.Default file in Visual Studio and I'm trying to use it for storing user settings. I made a string property called PortName with scope User, like this: PUbK2f2.png.

When I'm trying to write a new value to that property, or read the current value after publishing my app, I get a SettingsPropertyNotFoundException - "The settings property PortName was not found", just like it doesn't exist. Screenshot: g8q0gOP.png

public static string PortName {get; set;}

public static void LoadUserSettings()
{
    try
    {
        PortName = Properties.Settings.Default["PortName"].ToString();
    }
    catch (Exception ex)
    {
        MessageBox.Show($"{ex.Message}");
    }
}

When I test this locally, it works just fine - the setting is saved correctly, both in DEBUG and RELEASE mode.

When I publish the app and do the same with it, the error occurs.

How to make sure that the setting PortName exists on the client's end?

Developer technologies | Windows Presentation Foundation
Developer technologies | C#
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Viorel 122.6K Reputation points
    2021-03-03T16:54:40.993+00:00

    The Debug and Release folders on your machine contain the built executable (.exe), as well as a configuration file (.exe.config), which includes the settings. Maybe this file was missing on target machine? Check if such file was published. You can also try copying it manually to check if it works.


  2. DaisyTian-1203 11,646 Reputation points
    2021-03-04T08:08:39.14+00:00

    Please add default settings by steps: Right click the project> Choose the Properties> Go to Settings Tab > Click This project does not contain a default settings file, Click here to create on. The your project directory is as follows:
    74179-capture.png
    Then you can add PortName in it and used it as in the .net framework projects before


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.