[英]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.
我有一个控制台应用程序,它从 app.config 读取 SQL 连接。 It works fine in Visual Studio.
它在 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.
当我将三个项目移动到一个目录进行测试时,.exe、app.config和它需要的水晶报告到function,它不会从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.它轰炸了 var connectionString 行,出现未处理的异常 Object 引用未设置为 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.这是因为 app.config 在编译时被重命名为 YourAppName.exe.config。 Look in your bin/debug folder or bin/release folder.
查看您的 bin/debug 文件夹或 bin/release 文件夹。 There you find the used config-files
在那里你可以找到使用的配置文件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.