Reading dll.config (not app.config!) from a plugin module

You will need to load the x.dll.config (with the Configuration API) yourself. All the automatic file handling (including the .Settings) is all about machine.config/y.exe.config/user-settings. To open a named config file: Reference System.Configuration.dll assembly. Using System.Configuration Create code like: Configuration GetDllConfiguration(Assembly targetAsm) { var configFile = targetAsm.Location + “.config”; var map = new ExeConfigurationFileMap { ExeConfigFilename … Read more

Restoring Window Size/Position With Multiple Monitors

Try this code. Points of interest: Checks if the window is (partially) visible on any screen’s working area. E.g. dragging it behind the task bar or moving it completely offscreen resets the position to windows default. Saves the correct bounds even if the Form is minimized or maximized (common error) Saves the WindowState correctly. Saving … Read more

how to get value from appsettings.json

So there are really two ways to go about this. Option 1 : Options Class You have an appsettings.json file : { “myConfiguration”: { “myProperty”: true } } You create a Configuration POCO like so : public class MyConfiguration { public bool MyProperty { get; set; } } In your startup.cs you have something in … Read more

Read appsettings json values in .NET Core Test Project

This is based on the blog post Using Configuration files in .NET Core Unit Test Projects (written for .NET Core 1.0). Create (or copy) the appsettings.test.json in the Integration test project root directory, and in properties specify “Build Action” as Content and “Copy if newer” to Output Directory. Note that itโ€™s better to have file … Read more

ConfigurationManager.AppSettings – How to modify and save?

I know I’m late ๐Ÿ™‚ But this how i do it: public static void AddOrUpdateAppSettings(string key, string value) { try { var configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); var settings = configFile.AppSettings.Settings; if (settings[key] == null) { settings.Add(key, value); } else { settings[key].Value = value; } configFile.Save(ConfigurationSaveMode.Modified); ConfigurationManager.RefreshSection(configFile.AppSettings.SectionInformation.Name); } catch (ConfigurationErrorsException) { Console.WriteLine(“Error writing app settings”); } } … Read more

ASP.NET Core appsettings.json update in code

Basically you can set the values in IConfiguration like this: IConfiguration configuration = … // … configuration[“key”] = “value”; The issue there is that e.g. the JsonConfigurationProvider does not implement the saving of the configuration into the file. As you can see in the source it does not override the Set method of ConfigurationProvider. (see … Read more

What is the difference between app.config file and XYZ.settings file?

UPDATE: In ASP.NET Core Land, configuration is no longer managed via either of these – see this fantastic writeup from Travis Illig with the a-z on Microsoft.Extension.Configuration and Microsoft.Extensions.Configuration.Binder which are effectively a superset of all this Settings (Both from a .settings set and Configuration.AppSettings), are stored in the .config file [alongside lots of other … Read more

Change Azure website app settings from code

You can also use the Azure Fluent Api. using Microsoft.Azure.Management.Fluent; using Microsoft.Azure.Management.ResourceManager.Fluent; using Microsoft.Azure.Management.ResourceManager.Fluent.Authentication; using Microsoft.Azure.Management.ResourceManager.Fluent.Core; … public void UpdateSetting(string key, string value) { string tenantId = “a5fd91ad-….-….-….-…………”; string clientSecret = “8a9mSPas………………………………=”; string clientId = “3030efa6-….-….-….-…………”; string subscriptionId = “a4a5aff6-….-….-….-…………”; var azureCredentials = new AzureCredentials(new ServicePrincipalLoginInformation { ClientId = clientId, ClientSecret = clientSecret }, tenantId, … Read more

manual language selection in an iOS-App (iPhone and iPad)

In the meantime I did find a solution for my problem on myself: I created a new class “LocalizeHelper”: Header LocalizeHelper.h //LocalizeHelper.h #import <Foundation/Foundation.h> // some macros (optional, but makes life easy) // Use “LocalizedString(key)” the same way you would use “NSLocalizedString(key,comment)” #define LocalizedString(key) [[LocalizeHelper sharedLocalSystem] localizedStringForKey:(key)] // “language” can be (for american english): “en”, … Read more