8

I'm using .Net Standard 1.5 and want to read some values out of my config. However the following line

ConfigurationManager.AppSettings["Foo"]

gives me the following compile time error:

CS7069 Reference to type 'NameValueCollection' claims it is defined in 'System', but it could not be found

I thought that maybe in .Net Standard there is another way to read from AppSettings, but I haven't found anything on that topic.

Athari
  • 33,702
  • 16
  • 105
  • 146
wertzui
  • 5,148
  • 3
  • 31
  • 51
  • I too would like a means of achieving what `ConfigurationManager.AppSettings` does under netstandard, in order to port a library from net35, so I opened a bounty on your question. – Drew Noakes Dec 09 '16 at 04:30
  • 2
    The configuration system for .NET Standard has changed drastically. https://colinmackay.scot/2016/07/03/application-configuration-in-net-core-part-1/ – Paul Oliver Dec 09 '16 at 19:42
  • @PaulOliver, yes it has. However I have a library that has, for many years, supported app settings from the .config file. I would like to port it to netstandard without breaking users' code. Is there a polyfill for this API? – Drew Noakes Dec 10 '16 at 11:27
  • 1
    I believe you're going to need to build your library with two targets. One that targets net45 and another that targets netstandard1.X. The one that targets net45 will still have access to the `System.ConfigurationManager` API and will support appsettings. For your users that support .NET Core you'll use the newer `IOptions` approach. Then use compiler directives to support both. As an example, I've seen this approach in the [AWS SDK for .NET](https://github.com/aws/aws-sdk-net). – Paul Oliver Dec 21 '16 at 17:54

0 Answers0