C# System.Configuration.ConfigurationErrorsException
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12990706/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
System.Configuration.ConfigurationErrorsException
提问by Expecto
I have a form that has a few text boxes, you input some values into the text boxes and then when you press submit it saves the values to a file. However when I press submit, I get the following exception.
我有一个有几个文本框的表单,你在文本框中输入一些值,然后当你按下提交时,它会将值保存到一个文件中。但是,当我按下提交时,出现以下异常。
System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize ---> System.Configuration.ConfigurationErrorsException: Unrecognized configuration section add. (C:\Program Files (x86)\Default Company Name\Setup\HomeInventory2.exe.Config line 3)
at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors)
at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors()
at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
--- End of inner exception stack trace ---
at HomeInventory2.Services.Factory.GetService(String servicename) in C:\Users\Protego\documents\visual studio 2010\Projects\HomeInventory2\HomeInventory2\Services\Factory.cs:line 37
at HomeInventory2.Business.Manager.GetService(String name) in C:\Users\Protego\documents\visual studio 2010\Projects\HomeInventory2\HomeInventory2\Business\Manager.cs:line 14
at HomeInventory2.Business.InventoryMngr.Create(CreateInventory inv) in C:\Users\Protego\documents\visual studio 2010\Projects\HomeInventory2\HomeInventory2\Business\InventoryMngr.cs:line 19
at HomeInventory2.Form1.submitButton_Click(Object sender, EventArgs e) in C:\Users\Protego\documents\visual studio 2010\Projects\HomeInventory2\HomeInventory2\Form1.cs:line 52
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
If I am reading it correctly, the problem is in my App.config file. But I don't see any problem in that file - which is as follows.
如果我没看错,问题出在我的 App.config 文件中。但是我在该文件中没有看到任何问题 - 如下所示。
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<add key="InventorySvc" value="HomeInventory2.Services.InventorySvc" />
</configuration>
采纳答案by iefpw
The <add keyshould be inside like <appSettings>There is no configuration->add. It should be like configuration->appsettings->add.
本<add key应该是里面好像<appSettings>没有配置- >添加。它应该像配置->应用设置->添加。
回答by Sergey Berezovskiy
Your configuration file should look like this:
您的配置文件应如下所示:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="InventorySvc" value="HomeInventory2.Services.InventorySvc"/>
</appSettings>
</configuration>
appSettings- one of predefined configuration sections in .NET
appSettings- .NET 中预定义的配置部分之一

