如何使用应用程序/程序集属性

发布于 2024-10-01 14:11:11 字数 2371 浏览 1 评论 0原文

我正在编写一个由两个项目组成的解决方案,其中包含一个专为重用而设计的类库,以及一个将使用所述类库的应用程序。该库有一个属性文件,库本身和应用程序都需要该文件。不幸的是,当我尝试以“明显”的方式实现这一点时,通过将属性保留在类库中并通过完全指定 LibraryName.Properties... 从应用程序中访问它,它失败了(这只发生了)表明本能并不能很好地替代知识)。

我收到以下错误:

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.GetSection(String sectionName)
       at System.Configuration.PrivilegedConfigurationManager.GetSection(String sectionName)
       at System.Diagnostics.DiagnosticsConfiguration.GetConfigSection()
       at System.Diagnostics.DiagnosticsConfiguration.Initialize()
       at System.Diagnostics.DiagnosticsConfiguration.get_IndentSize()
       at System.Diagnostics.TraceInternal.InitializeSettings()
       at System.Diagnostics.TraceInternal.get_Listeners()
  InnerException: System.Configuration.ConfigurationErrorsException
   Message=Unrecognized configuration section userSettings. (C:\Users\CPFOHL\AppData\Local\CompanyName\ProductName.vshost.exe_Url_irhjcfvtmdm11v2ub0re3en5hgllqjz4\10.0.0.0\user.config line 3)
   Source=System.Configuration
   BareMessage=Unrecognized configuration section userSettings.
   Filename=C:\Users\CPFOHL\AppData\Local\CompanyName\ProductName.vshost.exe_Url_irhjcfvtmdm11v2ub0re3en5hgllqjz4\10.0.0.0\user.config
   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: 

我认为要分享的唯一其他信息是我在单独的解决方案中拥有两个项目,并且我使用“添加现有”添加了库,但这感觉不像错误。我

确信有一个简单的答案,如果我可以发布任何额外的信息,请告诉我。


[编辑] 我很确定设置配置正确。直到我将它们转移到一个单独的解决方案为止。然后我将它们移回原处,并一直在后悔......当我在“设置”编辑器中单击“同步”时,我得到以下信息:

No user.config files were found in any of the following locations:

然后它列出了它所查看的所有位置(主要在 User/CPFOHL/AppData 中)。我希望这有帮助。

I'm writing a two-project solution with a class library designed for re-use, and an application which will consume said class library. The library has a Properties file which is needed both in the library itself and in the application. Unfortunately when I tried to implement this the "obvious" way, by keeping the properties in the Class library and accessing it from the application by fully specifying LibraryName.Properties..., it failed (which only goes to show that instinct is a poor substitute for knowledge).

I'm getting the following error:

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.GetSection(String sectionName)
       at System.Configuration.PrivilegedConfigurationManager.GetSection(String sectionName)
       at System.Diagnostics.DiagnosticsConfiguration.GetConfigSection()
       at System.Diagnostics.DiagnosticsConfiguration.Initialize()
       at System.Diagnostics.DiagnosticsConfiguration.get_IndentSize()
       at System.Diagnostics.TraceInternal.InitializeSettings()
       at System.Diagnostics.TraceInternal.get_Listeners()
  InnerException: System.Configuration.ConfigurationErrorsException
   Message=Unrecognized configuration section userSettings. (C:\Users\CPFOHL\AppData\Local\CompanyName\ProductName.vshost.exe_Url_irhjcfvtmdm11v2ub0re3en5hgllqjz4\10.0.0.0\user.config line 3)
   Source=System.Configuration
   BareMessage=Unrecognized configuration section userSettings.
   Filename=C:\Users\CPFOHL\AppData\Local\CompanyName\ProductName.vshost.exe_Url_irhjcfvtmdm11v2ub0re3en5hgllqjz4\10.0.0.0\user.config
   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: 

The only other information I can think to share is that I have the two projects in separate solutions, and I added the Library with "Add Existing," but that doesn't feel like the error...

I'm sure there's an easy answer, let me know if I can post any extra information.


[EDIT]
I'm pretty sure that the Settings are configured correctly. The worked until I moved them to a separate solution. I then moved them back in and have been regretting it since... When I click Synchronize in the Settings editor I get the following:

No user.config files were found in any of the following locations:

It then lists all the places it looked (mostly in User/CPFOHL/AppData). I hope that helps.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笙痞 2024-10-08 14:11:11

您可以尝试删除C:\Users\CPFOHL\AppData\Local\CompanyName\ProductName.vshost.exe_Url_irhjcfvtmdm11v2ub0re3en5hgllqjz4\10.0.0.0\user.config

也许您更改了其中一个属性和旧的属性的类型其中一个已持久保存到每个用户存储中。

Can you try deleting C:\Users\CPFOHL\AppData\Local\CompanyName\ProductName.vshost.exe_Url_irhjcfvtmdm11v2ub0re3en5hgllqjz4\10.0.0.0\user.config

Perhaps you changed the type on one of the properties and an old one was already persisted to the per user store.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文