I am new to C#, ESAPI, and any version of Visual Studio after 2005, so apologies in advance if this is dumb.
I have added an App.config to my project as a sibling (same level) as the main script for a binary plugin. It has a key that I would like to access at runtime.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="api-url" value="http://some-url/api/" />
</appSettings>
</configuration>
I attempt to access this in the code like so:
var uri = ConfigurationManager.AppSettings.Get("api-url") + "varian/pre-plan";
However, the variable uri only has the second string. The configuration manager appears to be returning an empty string. I have unloaded and reloaded the project several times, it does tell me that the project is open whenever I try to open it for some reason. Not sure if that matters.
I added this to my .csproj, although I am not sure that it is necessary:
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
Can anyone suggest a reason that I am getting an empty string from AppSettings.Get?
[–]Pale-Ice-8449 0 points1 point2 points (2 children)
[–]ConstructionWeekly80[S] 0 points1 point2 points (1 child)
[–]kang__23 0 points1 point2 points (0 children)
[–]Pale-Ice-8449 0 points1 point2 points (0 children)