runtime icon indicating copy to clipboard operation
runtime copied to clipboard

# in file directory name causes System.Configuration.ConfigurationManager not to discover appsetings for .net core 2.0 app

Open TrevorFradsham opened this issue 8 years ago • 6 comments

The path to my project files has a hashtag # in it and I spent many hours trying to find out why my .net core 2.0 console app was not able to access the System.Configuration.ConfigurationManager.AppSettings. I thought it was a misspelling of the strings but when I moved the project folder out of the sub-directory with the hashtag, everything worked find.

\code\c#\projectfolder \code\projectfolder

I figured out the issue when I wrote a piece of code to see if I could add a setting key value pair, when the project was in the folder with the # (\code\c#\projectfolder). It resulted in a .config file being created in \code\c.config. I did not given any name to the config file. The setting should have appeared in the following file. \code\c#\projectname\bin\Debug\netcoreapp2.0\projectname.dll.config

Here is the code I had tested:

    private static void _setConfigurationSettings()
    {
        string key = "MyCustomSettings2";
        try
        {
            var configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            var settings = configFile.AppSettings.Settings;
            if (settings[key] == null)
            {
                settings.Add("MyCustomSettings2", "Hi This is my setting");
            }
            else
            {
                settings[key].Value = "My Setting hasChanged";
            }
            configFile.Save(ConfigurationSaveMode.Modified);
            ConfigurationManager.RefreshSection(configFile.AppSettings.SectionInformation.Name);
        }
        catch (ConfigurationErrorsException ex)
        {
            Console.WriteLine($"ERROR: {ex.ToString()}\n");
        }
    }

TrevorFradsham avatar Apr 15 '18 18:04 TrevorFradsham

@anipik can you localize this? I wonder whether it's URI related.

danmoseley avatar Apr 15 '18 23:04 danmoseley

I am on it.

Anipik avatar Apr 16 '18 00:04 Anipik

@danmosemsft I am able to repro the bug on 2.0 as well as 2.1

Anipik avatar Apr 16 '18 22:04 Anipik

@TrevorFradsham have you tried using the latest version of System.Configuration.ConfigurationManager nuget package? The problem is reproducible in version 4.4.1 but not anymore in 4.5.0-preview2-26406-04

maryamariyan avatar Apr 26 '18 17:04 maryamariyan

‎Will give it a try

Thanks Trevor From: Maryam Ariyan Sent: Thursday, April 26, 2018 3:27 PM To: dotnet/corefx Reply To: dotnet/corefx Cc: Fradsham, Trevor; Mention Subject: Re: [dotnet/corefx] # in file directory name causes System.Configuration.ConfigurationManager not to discover appsetings for .net core 2.0 app (#29126)

@TrevorFradshamhttps://github.com/TrevorFradsham have you tried using the latest version of System.Configuration.ConfigurationManager nuget package. The problem is reproducible in version 4.4.1 but not anymore in 4.5.0-preview2-26406-04

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/dotnet/corefx/issues/29126#issuecomment-384732036, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AfcE35R9cOJeLs-tJFJ-1FGF2v-rXr1bks5tsgqSgaJpZM4TVl6Q.

TrevorFradsham avatar Apr 27 '18 09:04 TrevorFradsham

Closing this issue as it is fixed on the newer version. @TrevorFradsham you can reopen if you still find an issue.

maryamariyan avatar May 01 '18 00:05 maryamariyan