简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM