如何使用应用程序/程序集属性
我正在编写一个由两个项目组成的解决方案,其中包含一个专为重用而设计的类库,以及一个将使用所述类库的应用程序。该库有一个属性文件,库本身和应用程序都需要该文件。不幸的是,当我尝试以“明显”的方式实现这一点时,通过将属性保留在类库中并通过完全指定 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试删除
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.