Steve Cross
Steve Cross

Reputation: 99

How do I get my c# console application to run with an app.config?

This is peculiar to me although I'm sure I'm missing something simple and basic. I have a console application that reads a SQL connection from an app.config. It works fine in Visual Studio. When I move three items to a directory to test, the .exe, the app.config, and the crystal report that it needs to function, it won't read from the app.config.

Console.WriteLine("about to get connection string...");
var connectionString = ConfigurationManager.ConnectionStrings["InformConnectionString"].ConnectionString;

It bombs on the var connectionString line with an unhandled exception Object reference not set to an instance of an object. Again, works fine in the development environment, just not in the production directory.

Upvotes: 1

Views: 209

Answers (1)

Anders H
Anders H

Reputation: 411

It is because the app.config is renamed to YourAppName.exe.config when it is compiled. Look in your bin/debug folder or bin/release folder. There you find the used config-files

Upvotes: 1

Related Questions