.NET配置截面设计 - 我的收藏? [英] .NET Configuration Section Designer - Where is my collection?

查看:107
本文介绍了.NET配置截面设计 - 我的收藏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是配置截面设计为.NET来构建一个简单的 ConfigurationElementCollection 。它的出现的一切都建立蛮好和code是自动生成的,因为子元素是可见的与智能感知。

I am using the Configuration Section Designer for .NET to build a simple ConfigurationElementCollection. It appears that everything builds just fine and the code is automatically generated since the sub-elements are visible with Intellisense.

不幸的是,尽管我已经添加元素来配置部分集合,他们不会在运行时存在;它显示了集合的长度属性为0 - 即集合是空的,即使,你可以在我的示例XML看,我已经清楚地把它们放在那里:

Unfortunately, even though I have added elements to the collection in the configuration section, they do not exist at run-time; it shows the collection's Length property to be 0 - i.e. the collection is empty even though, as you can see in my example XML, I have clearly put them there:

<logParserSettings xmlns="LogParser">
  <domainControllers>
    <domainController ID="0" name="Local" serverType="Local" enabled="true"/>
    <domainController ID="1" name="DC1" serverType="WindowsServer2003" enabled="false" />
    <domainController ID="2" name="DC2" serverType="WindowsServer2008" enabled="false" />
  </domainControllers>
</logParserSettings>

其他

  • 在设计师,我只有你在这里看到,一个配置节,一个 ConfigurationElementCollection ,和的ConfigurationElement - 有没有额外的配置元素/节/组
  • 在我没有加入或在运行时消除任何
  • 在我曾经尝试都发生,而不是生成辛格尔顿属性,但无论是单实例,也没有设置类的一个实例似乎工作
  • id属性,在是关键属性设置为true,而所有其他属性都标适用于需要
  • Miscellaneous

    • In the designer, all I have is what you see here, a ConfigurationSection, a ConfigurationElementCollection, and a ConfigurationElement - there are no additional configuration elements/sections/groups
    • I am not adding or removing anything at run-time
    • I have tried both generating and not generating the Singleton property, but neither the singleton instance nor an instance of the settings class seem to work
    • For the ID attribute, the Is Key property is set to true, and all other attributes are marked true for Is Required
    • 有没有人碰到这个?如果是的话,做什么样的变化我必须做出得到这个工作打算?

      Has anyone ever run into this? If so, what change do I have to make to get this to work as intended?

      推荐答案

      嗯,我严重被指定有问题到特定的元素,当它变成了甚至没有了<$ C一个简单的测试属性过于复杂的真问题$ C>配置节将返回预期值。我也意识到,我无法访问的AppSettings ,这导致了激烈的线索。

      Well, I grossly overcomplicated the true issue by specifying the problem down to a specific element, when it turns out not even a simple test attribute on the ConfigurationSection would return an expected value. I also realized that I couldn't access AppSettings, which resulted in a raging clue.

      最终的原因是什么?该项目被编译为一个类库。配置文件是只适用于应用程序级别。自从我使用NUnit运行测试,从测试项​​目中的配置文件被覆盖了开发一个用于类库。这可能是显而易见的谁不停留在ASP.NET土地的任何开发人员。

      The ultimate cause? The project was compiled as a class library. Config files are only available at the application level. Since I was using NUnit to run the tests, the configuration file from the test project was overriding the development one for the class library. This is probably obvious to any developers who are not stuck in ASP.NET land.

      通过将以下 configSection 的app.config 测试项目中的:

      By adding the following configSection to the app.config within the test project:

      <section name="customConfigSection" type="ClassLibraryNamespace.SettingsClass, ClassLibraryNamespace"/>
      

      和填写相应部分,该数据可能会按预期的方式访问。

      and filling in the corresponding section, the data could be accessed as expected.

      希望这将节省别人时间的调试。

      Hopefully, this will save someone hours of debugging.

      这篇关于.NET配置截面设计 - 我的收藏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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