且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ConfigurationManager 返回 null 而不是字符串值

更新时间:2023-02-06 12:48:52

您是否确保将配置文件正确放置在您运行应用程序的目录中?那个目录中真的有一个名为 .exe.config 的文件吗?

Did you ensure that the config file is placed correctly at the directory from which you're running the application? Is there actually a file called <app name>.exe.config in that directory?

我只是在这里猜测 - 也许你在不同的项目中添加了 App.Config 文件然后你的 exe 程序集项目......?

I'm just guessing here - maybe you added the App.Config file in a different project then your exe assembly project...?

顺便说一下,我将您的代码和 App.Config 按原样复制到了一个干净的项目中,这段代码对我有用.所以我会看配置文件本身的方向,而不是代码.代码没问题...

By the way, I copied your code and App.Config as is to a clean project, and this code worked for me. So I'd look in the direction of the config file itself and not in the code. The code is fine...

希望这会有所帮助,