ConfigurationManager.AppSettings generates compile time error on .Net Standard 1.5
Asked Answered
R

0

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.

Realize answered 11/11, 2016 at 15:34 Comment(4)
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.Turnover
The configuration system for .NET Standard has changed drastically. colinmackay.scot/2016/07/03/…Underthecounter
@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?Turnover
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.Underthecounter

© 2022 - 2024 — McMap. All rights reserved.