在我的winform应用程序中,我正在尝试添加userSetting,尽管appSettings也出现了错误.当添加设置时,我得到一个抛出的异常,说:"配置系统无法初始化",内部异常"无法识别的配置部分userSetting"
例外细节:
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.ConfigurationManager.PrepareConfigSystem() 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 Settings.get_ApplicationData() in \Properties\Settings.Designer.cs:line 41 at Common.Initialize.IsSettingsInitialized() at SurveyClient.Program.Main() at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException: System.Configuration.ConfigurationErrorsException Message="Unrecognized configuration section userSettings. Source="System.Configuration" BareMessage="Unrecognized configuration section userSettings." Line=3 StackTrace: at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal) at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors) at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors() at System.Configuration.ClientConfigurationSystem.OnConfigRemoved(Object sender, InternalConfigEventArgs e) InnerException:
beluga.. 27
我有一些用户设置,然后删除所有这些设置并开始看到此异常 - 但仅在运行应用程序时没有调试.调试应用程序时它工作正常.原因是用户级设置在本地应用程序数据文件夹中"缓存",实际上不会从MYAPP.exe.config中读取.所以我做的是去C:\ Users\MYUSERNAME\AppData\Local\MYCOMPANY\MYAPP.exe_Url_longnastyhash9982749827349879\1.0.0.0\user.config(这是在Win7上,路径依赖于操作系统)并删除该文件夹(使用完全长的哈希).例外消失了.顺便说一句,根据您的设置设置,此user.config文件可能位于\ AppData\Local或\ AppData\Roaming下.
我有一些用户设置,然后删除所有这些设置并开始看到此异常 - 但仅在运行应用程序时没有调试.调试应用程序时它工作正常.原因是用户级设置在本地应用程序数据文件夹中"缓存",实际上不会从MYAPP.exe.config中读取.所以我做的是去C:\ Users\MYUSERNAME\AppData\Local\MYCOMPANY\MYAPP.exe_Url_longnastyhash9982749827349879\1.0.0.0\user.config(这是在Win7上,路径依赖于操作系统)并删除该文件夹(使用完全长的哈希).例外消失了.顺便说一句,根据您的设置设置,此user.config文件可能位于\ AppData\Local或\ AppData\Roaming下.
尝试检查app.config(myapp.exe.config一旦部署)文件是否存在并且位于顶部(可能还有其他位)
当我编写App.Config(愚蠢)时,我收到此错误,如下所示.
请注意,没有appSettings?我曾经经常做这个错误......