访问settings.settings时出现“配置系统初始化失败”的错误。

7

自从删除了原始的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 -> 冷静。


奇怪,这个错误发生在哪里(例如运行时、设计师),你有任何重现步骤吗?因为我刚试着删除了设置文件但保留了生成的类,它可以正常工作。 - Chris Chilvers
你能调试错误并在“配置系统初始化失败”异常发生的地方中断吗?如果可以,内部异常是否有进一步的信息说明问题的原因? - adrianbanks
听起来好像是反序列化出现了问题,Adrian,请检查内部异常或任何其他可能包含完整错误消息的细节。 - Chris Chilvers
请问一个关于异常的问题,是否真的需要发布完整的异常信息这么高级的概念? - John Saunders
1
@Nona:我很抱歉。我从未想过有人会将异常视为不透明的东西,只是一个名称和消息。实际上,我确实不理解现在人们如何学习.NET(“我不理解”的部分显然是我的错)。 - John Saunders
3个回答

8
这是你的线索:

“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行。

6
我也遇到过这个问题。解决方法是删除Users\yourUserName\AppData\Local\YourAppName文件夹中的所有内容。
似乎当某些设置被保存为用户范围的设置,然后你将其(在Settings.settings设计器中)转换为应用程序范围的设置时,某些东西就出了问题,VS不知道从哪里获取设置值。
现在,如果你只是将一些设置添加为用户范围设置,然后将其转换为应用程序范围设置(而不通过编程更改并保存它),一切都会正常进行。但是,如果你使用Properties.Settings.Default.Save()保存设置,然后尝试将其转换为应用程序范围,则会开始出现问题。
希望这可以帮到你。

谢谢,我不小心将某些设置设为用户范围。 - Patrick Allwood

0

这个问题已经存在了3年,但问题从未过时...如果有人偶然遇到这个问题..

当我将一个项目的配置部分复制到另一个项目的app.config中,并没有完全复制命名空间时,我遇到了同样的问题..

<membership>
    <providers> ..

而不是

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

请确保您使用完整的集合。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接