C#错误:无法识别的配置节userSettings-停止程序读取user.config吗? [英] c# error:Unrecognized configuration section userSettings - stop program reading user.config?

查看:653
本文介绍了C#错误:无法识别的配置节userSettings-停止程序读取user.config吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的c#表单应用程序(使用.NET 4.0在VS2010中创建)中,我使用应用程序设置来存储输出路径.

In my c# form application (created in VS2010, using .NET 4.0) I use an application setting to store an output path.

以前,此设置是使用用户范围配置的,但我必须将其范围更改为应用程序.

Previously this setting was configured with a user scope, but I had to change its scope to application.

完成此操作后,我现在在启动表单时收到无法识别的配置节userSettings 错误(请注意,该程序之前已执行,且设置范围设置为user)

After doing this I now get an Unrecognized configuration section userSettings error on start up of the form (note the program has been executed before with the setting's scope set to user):

InnerException: System.Configuration.ConfigurationErrorsException
   Message=Unrecognized configuration section userSettings. (C:\Documents and Settings\Administrator\Local Settings\Application Data\CallCenterForm\CallCenterForm.vshost.exe_StrongName_bplf30wziudnpq0knzaacfuyomd5rv45\1.0.0.0\user.config line 3)
   Source=System.Configuration
   BareMessage=Unrecognized configuration section userSettings.
   Filename=C:\Documents and Settings\Administrator\Local Settings\Application Data\CallCenterForm\CallCenterForm.vshost.exe_StrongName_bplf30wziudnpq0knzaacfuyomd5rv45\1.0.0.0\user.config

因此,在进行了一些浏览之后,这似乎是由系统上仍然存在的旧user.config文件引起的,导致程序读取了该文件并引发了错误(我不确定实际的根本问题是什么).我还可以确认删除文件后问题就消失了.

So after doing some browsing this seems to be caused by the old user.config file still existing on the system, causing the program to read it and throw an error (I'm not sure what the actual underlying problem is). I can also confirm that when I remove the file the problem goes away.

这带给我的问题是,有什么办法可以更改程序,使其不会读取旧的user.config文件,因为手动删除它并不理想,因为该程序已在多个生产环境中投入生产.系统.

Which brings me to my question, is there a way I can change the program so that it won't read the old user.config file, because deleting it manually isn't ideal as the program is already in production on multiple systems.

很抱歉,如果已解决此问题,但我找不到答案.

Apologies if this has been covered, but I couldn't find an answer.

以防万一,这是我的App.config文件的内容:

In case it's helpful here's the contents of my App.config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
      <section name="CallCenterForm.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    </sectionGroup>
  </configSections>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0"/>
  </startup>
  <applicationSettings>
    <CallCenterForm.Properties.Settings>
      <setting name="saved_output_dir" serializeAs="String">
        <value>c:\</value>
      </setting>
    </CallCenterForm.Properties.Settings>
  </applicationSettings>
</configuration>

推荐答案

我今天自己遇到了这个错误.解决方案是进入项目属性的程序集信息"对话框,并推进程序集和文件版本信息(例如,从1.0.0.0到1.0.1.0),保存更改并重建应用程序.由于新版本中没有用户设置,因此这将导致编译器重新评估配置,并使应用程序避免创建和读取与新版本相对应的新user.config文件.

I ran into this error myself today. The solution was to go into the Assembly Information dialogue of the project's properties and advance the assembly and file version info (ex. 1.0.0.0 to 1.0.1.0), save the changes, and rebuild the application. This will cause the compiler to reevaluate the configuration and cause the application to refrain from creating and reading a new user.config file corresponding to the new version due to there being no user settings in the new version.

这篇关于C#错误:无法识别的配置节userSettings-停止程序读取user.config吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆