How to hardcode and read a string array in appSettings.json?

Indexer of a section returns string by exact key match, and since array values have keys with postfixes, there is nothing to match given key and you are getting null. To get it work you may use something like this var section = configuration.GetSection($”{APP_SETTINGS_SECTION}:{APP_SETTINGS_KEY}”); var folders = section.Get<string[]>(); And check this for more options.

Value cannot be null. Parameter name: connectionString appsettings.json in starter

First of all, the “Data”: { “ConnectionStrings”: { “DefaultConnection”: “Data Source=server;Initial Catalog=dbase;Trusted_Connection=True;MultipleActiveResultSets=true”}, } Is slightly different from the structure you get when you add a “Asp.NET Configuration File” in Visual Studio. When you do that you get “ConnectionStrings”: { “DefaultConnection”: “Data Source=server;Initial Catalog=dbase;Trusted_Connection=True;MultipleActiveResultSets=true”}, without the “Data” JavaScript Object. So that’s why the extension method isn’t … Read more

Find current country from iPhone device

To find the country of the user’s chosen language: NSLocale *currentLocale = [NSLocale currentLocale]; // get the current locale. NSString *countryCode = [currentLocale objectForKey:NSLocaleCountryCode]; // get country code, e.g. ES (Spain), FR (France), etc. In Swift: let currentLocale = NSLocale.currentLocale() let countryCode = currentLocale.objectForKey(NSLocaleCountryCode) as? String If you want to find the country code of … Read more

appSettings vs applicationSettings. appSettings outdated? [duplicate]

This has been discussed before here: Pros and cons of appSettings vs applicationSettings (.NET app.config). As for your questions: The older one is <appSettings>, it was around before 2.0, <applicationSettings> became available in 2.0. Advantage? When I’m editing a value, or adding a value on a server where the best tool is notepad <applicationSettings> is … Read more

Multiple AppSettings files, is it possible?

You can’t have more than one appsettings because that’s the name of a section. You can add a new section though that uses the same kind of section definition as appsettings. E.g., <configuration> <configSections> <section name=”DatabaseConfig” type=”System.Configuration.NameValueFileSectionHandler, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089″/> </configSections> …. <DatabaseConfig> <add key=”Whatever” value=”stuff”/> </DatabaseConfig> </configuration>

How to get values from appsettings.json in a console application using .NET Core?

Your example is mixing in some ASP NET Core approaches that expect your code to be hosted. To minimally solve the issue of getting options or settings from a JSON configuration, consider the following: A config.json file, set to “Copy to Output Directory” so that it is included with the build: { “MyFirstClass”: { “Option1”: … Read more