C# DLL config file

Im trying to add an app.config file to my DLL, but all attempts have failed. According to MusicGenesis in ‘Putting configuration information in a DLL’ this should not be a problem. So obviously I’m doing something wrong… The following code should return my ConnectionString from my DLL: return ConfigurationManager.AppSettings[“ConnectionString”]; However, when I copy the app.config … Read more

Is ConfigurationManager.AppSettings available in .NET Core 2.0?

I’ve got a method that reads settings from my config file like this: var value = ConfigurationManager.AppSettings[key]; It compiles fine when targeting .NET Standard 2.0 only. Now I need multiple targets, so I updated my project file with: <TargetFrameworks>netcoreapp2.0;net461;netstandard2.0</TargetFrameworks> But now, the compilation fails for netcoreapp2.0 with the following error message: Error CS0103 The name … Read more

What does ‘useLegacyV2RuntimeActivationPolicy’ do in the .NET 4 config?

While converting a project that used SlimDX, and therefore has unmanaged code, to .NET 4.0 I ran into the following error: Mixed mode assembly is built against version ‘v2.0.50727’ of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information. Googling around gave me the solution, which is to add this … Read more

How to read AppSettings values from a .json file in ASP.NET Core

I have set up my AppSettings data in file appsettings/Config .json like this: { “AppSettings”: { “token”: “1234” } } I have searched online on how to read AppSettings values from .json file, but I could not get anything useful. I tried: var configuration = new Configuration(); var appSettings = configuration.Get(“AppSettings”); // null var token … Read more

Get connection string from App.config

var connection = ConnectionFactory.GetConnection( ConfigurationManager.ConnectionStrings[“Test”] .ConnectionString, DataBaseProvider); And this is my App.config: <?xml version=”1.0″ encoding=”utf-8″ ?> <configuration> <connectionStrings> <add name=”Test” connectionString=”Data Source=.;Initial Catalog=OmidPayamak;Integrated Security=True” providerName=”System.Data.SqlClient” /> </connectionStrings> </configuration> But when my project runs this is my error: Object reference not set to an instance of an object. 22 Answers 22

App.Config Transformation for projects which are not Web Projects in Visual Studio?

For Visual Studio 2010 Web based application we have Config Transformation features by which we can maintain multiple configuration files for different environments. But the same feature is not available for App.Config files for Windows Services/WinForms or Console Application. There is a workaround available as suggested here: Applying XDT magic to App.Config. However it is … Read more