Quantcast
Channel: Active questions tagged config - Stack Overflow
Viewing all articles
Browse latest Browse all 5049

GetValue always getting null/default regardless of type

$
0
0

I noticed that the following statement produces a discrepancy.

public static string GetValidation(this IConfiguration self, string key)
{
  IConfigurationSection section = self.GetSection(key);

  string value1 = section.Value;
  string value2 = section.GetValue<string>(key);

  return "";
}

The corresponding section in the config has correctly set value and is correctly located using the specified path.

...
"SomePath": "Some value",
"AlsoTried": 13,
"AndEven": true,
...

The first value is as expected, the content of the node. The second is null. When I tried typing to integers and booleans, I got zero and falsity, i.e. defaults (of course I changed the value in the config file to non-string, e.g. 13 and true respectively.

I've scrutinized the docs and googled the issue, coming up with nothing useful.

What am I missing here (because I'm sure like a rat's behind it's not a bug in .NET, hehe)?


Viewing all articles
Browse latest Browse all 5049

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>