I'm initializing a System.IO.StreamReader by passing a string which contains a UNC Path, but the StreamReader ctor is prefixing the UNC path with the working directory, resulting in a System.IO.DirectoryNotFoundException.
The UNC path is stored in applicationSettings, with value:
\\networkShareMachine\Projects\hold\tst.csv
I'm getting the UNC from applicationSettings using this:
public static object GetValue(string settingName)
{
object result = null;
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
// find section
ClientSettingsSection configSection = config.SectionGroups[@"applicationSettings"].Sections["VCM.WPF.Properties.Settings"] as ClientSettingsSection;
var setting = configSection.Settings.Get(settingName).Value.ValueXml.InnerText;
result = setting;
return result;
}
}
Intellisense tells me the value of the "setting" variable is correct, except with doubled-up backslashes:
string setting = (string)Utils.SettingsReader.GetValue("CSVLocation");
\\\\networkShareMachine\\Projects\\hold\\tst.csv
Then, I new up a StreamReader by passing the UNC value into the ctor:
using (var streamReader = new StreamReader(path: setting))
{
...
}
I expect the stream reader to be initialized just like any other time, except I'm getting a
System.IO.DirectoryNotFoundException.
The reason why is because the UNC is being prefixed with the working directory like so:
'C:\Users\userName\source\repos\VCM\VCM.Models.Test\bin\Debug\\networkMachineName\Projects\hold\tst.csv'
It seems like the StreamReader ctor is prefixing the string itself. Why is it doing this and how can I prevent it?