带有“配置系统初始化失败"的 App.Config 错误 [英] App.Config errors with "Configuration system failed to initialize"
问题描述
我有一个在 .net 4.0 下用 C# 编写的控制台应用程序它有一堆变量,我想将它们移到 App.Config 中(因此它将全部放在一个地方).将这部分代码添加到 App.Config(在配置标签之间):
<预><代码><配置><应用设置><add key="RemoteDirectory" value="Some Text Here"/></appSettings></配置>在我的程序中尝试使用此代码进行测试
Console.WriteLine(ConfigurationManager.AppSettings["RemoteDirectory"]);
但我不断收到配置系统初始化失败"错误.
尝试查看内部异常以获取更多详细信息.当我遇到同样的问题时,它帮助了我.
此外,请检查您在项目中使用的 .net Framework 的格式是否正确.如果您使用的是 4.5 框架,它应该如下所示:
<add key="RemoteDirectory" value="Some Text Here"/></appSettings></配置>
I have a console application written in C# under .net 4.0 It has a bunch of variables which I want to move into App.Config (so it will be all in one place). Added this part of code to App.Config (between configuration tags):
<configuration>
<appSettings>
<add key="RemoteDirectory" value="Some Text Here"/>
</appSettings>
</configuration>
In my program trying to test it with this code
Console.WriteLine(ConfigurationManager.AppSettings["RemoteDirectory"]);
but I keep getting "Configuration system failed to initialize" error.
Try looking the Inner Exception for more detailed information. It helped me out when I had this same trouble.
Also, check if the format is correct for the .net Framework you are using on your project. If you're using the framework 4.5 it should look like the one below:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<appSettings>
<add key="RemoteDirectory" value="Some Text Here" />
</appSettings>
</configuration>
这篇关于带有“配置系统初始化失败"的 App.Config 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!