【问题标题】:"Configuration system failed to initialize" when accessing settings.settings访问 settings.settings 时出现“配置系统初始化失败”
【发布时间】:2010-11-21 19:27:34
【问题描述】:

自从删除原始的 settings.settings 文件后,我在设置功能方面遇到了无穷无尽的问题。我在 get 或 set 方法上收到“配置系统初始化失败”错误。有任何想法吗?谢谢。

    public static Settings Default {
        get {
            return defaultInstance;
        }
    }

    [global::System.Configuration.UserScopedSettingAttribute()]
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    [global::System.Configuration.DefaultSettingValueAttribute("Keywords.log")]
    public string KeywordsLog {
        get {
            return ((string)(this["KeywordsLog"]));
        }
        set {
            this["KeywordsLog"] = value;
        }
    }

问题位于 Settings.Designer.cs

Adrian Banks,恐怕我不知道如何进一步调试?它已经因错误而中断。如果有任何帮助,给定框的标题是“ConfigurationErrorsException”。

抱歉,我没有意识到您可以在 VS 中看到更多详细信息。

System.Configuration.ConfigurationErrorsException was unhandled
  Message="Configuration system failed to initialize"
  Source="System.Configuration"
  BareMessage="Configuration system failed to initialize"
  Line=0
  StackTrace:
       at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
       at System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem(String sectionName)
       at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.RefreshConfig(String sectionName)
       at System.Configuration.ConfigurationManager.RefreshSection(String sectionName)
       at System.Configuration.ClientSettingsStore.ReadSettings(String sectionName, Boolean isUserScoped)
       at System.Configuration.LocalFileSettingsProvider.GetPropertyValues(SettingsContext context, SettingsPropertyCollection properties)
       at System.Configuration.SettingsBase.GetPropertiesFromProvider(SettingsProvider provider)
       at System.Configuration.SettingsBase.GetPropertyValueByName(String propertyName)
       at System.Configuration.SettingsBase.get_Item(String propertyName)
       at System.Configuration.ApplicationSettingsBase.GetPropertyValue(String propertyName)
       at System.Configuration.ApplicationSettingsBase.get_Item(String propertyName)
       at READOO.Properties.Settings.get_KeywordsLog() in C:\Users\USER\Documents\Visual Studio 2008\Projects\READOO\READOO\Properties\Settings.Designer.cs:line 31
       at READOO.SettingsWindow..ctor() in C:\Users\USER\Documents\Visual Studio 2008\Projects\READOO\READOO\SettingsWindow.cs:line 19
       at READOO.WelcomeWindow.Settings_Click(Object sender, EventArgs e) in C:\Users\user\Documents\Visual Studio 2008\Projects\READOO\READOO\WelcomeWindow.cs:line 23
       at System.Windows.Forms.Control.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.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at READOO.Program.Main() in C:\Users\USER\Documents\Visual Studio 2008\Projects\READOO\READOO\Program.cs:line 18
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.Configuration.ConfigurationErrorsException
       Message="Section or group name 'READOO.Properties.Settings' is already defined. This can not be defined multiple times. (C:\\Users\\USER\\Documents\\Visual Studio 2008\\Projects\\READOO\\READOO\\bin\\Debug\\READOO.exe.config line 6)"
       Source="System.Configuration"
       BareMessage="Section or group name 'READOO.Properties.Settings' is already defined. This can not be defined multiple times."
       Filename="C:\\Users\\USER\\Documents\\Visual Studio 2008\\Projects\\READOO\\READOO\\bin\\Debug\\READOO.exe.config"
       Line=6
       StackTrace:
            at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
            at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors()
            at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
       InnerException: 

@ joan -> 冷静。

【问题讨论】:

  • 奇怪,这个错误发生在哪里(例如运行时,与设计器),您是否有任何重现的步骤。正如我刚刚尝试删除设置文件但保留生成的类并且它工作正常。
  • 能否调试一下出现“配置系统初始化失败”异常的地方?如果是这样,内部异常是否有任何关于导致问题的进一步信息?
  • 听起来有些东西可能无法像 Adrian 那样反序列化,检查内部异常或任何其他可能包含完整错误消息的详细信息。
  • 当你问一个关于异常的问题时,你应该发布完整的异常,这真的是一个高级概念吗?
  • @Nona:我很抱歉。我从来没有想过有人可能会收到异常并将其视为不透明的东西,只有一个名称和消息。事实上,我不明白这些天人们是如何学习 .NET 的(“我不明白”部分显然是我的错)。跨度>

标签: c# visual-studio-2008 settings


【解决方案1】:

这将是你的线索:

部分或组名称“READOO.Properties.Settings”已定义。这不能多次定义。 (C:\Users\Dylan\Documents\Visual Studio 2008\Projects\READOO\READOO\bin\Debug\READOO.exe.config 第 6 行)

您可能在该配置文件中的 <configSections> 定义中有 2 个 <section name="READOO.Properties.Settings"> 元素。

重复的条目很可能在所述配置文件的第 6 行。

【讨论】:

    【解决方案2】:

    这也发生在我身上。解决方案是删除 Users\yourUserName\AppData\Local\YourAppName 中的所有内容。

    似乎当某些设置被保存为设置的用户范围,然后你(在 Settings.settings 设计器中)将其设置为应用程序范围时,设置的东西搞砸了,VS 不知道从哪里获取设置值.

    现在,如果您只是将一些设置添加为用户范围设置,然后将其转换为应用程序范围设置(无需以编程方式更改和保存)- 一切正常。 但是,如果您使用 Properties.Settings.Default.Save() 保存设置,然后尝试将其转换为 Application 范围,它就会开始导致问题。

    希望对你有帮助。

    【讨论】:

    • 谢谢,我不小心为用户范围设置了一些设置。
    【解决方案3】:

    这个问题已经存在 3 年了,但问题永远不会过时 .. 以防万一 有人偶然发现了这个..

    我从复制配置部分时遇到了同样的问题 一个项目进入另一个项目的 app.config 并且无法复制 完整的命名空间..

    <membership>
        <providers> ..
    

    而不是

     <system.web>
       <membership>
           <providers> .. 
    

    确保使用全套。

    【讨论】:

      猜你喜欢
      • 2011-07-31
      • 2011-09-20
      • 1970-01-01
      • 1970-01-01
      • 2012-04-23
      • 2014-09-28
      相关资源
      最近更新 更多