相关疑难解决方法(0)

每个配置文件只能出现一次!为什么?

我得到以下例外:"每个配置文件只能出现一次.请参阅帮助主题以了解异常."

我的配置文件如下所示:

<configSections>
    <sectionGroup name="point.System">
        <section name="singleInstanceCache"
            type="xyz.Point.System.Configuration.SingleInstanceCache, Point.System" />
    </sectionGroup>
    <sectionGroup name="point.Services">
        <sectionGroup name="xServices" type="xyz.Point.Messaging.PointServiceConfiguration.PointServices, Barcap.FIA.Point.Messaging">
            <section name="xService"
                type="xyz.Point.Messaging.PointServiceConfiguration.PointService, Barcap.FIA.Point.Messaging" />
        </sectionGroup>
    </sectionGroup>
</configSections>

<point.Services>
    <xServices>
        <xService name="Service1" type="IService" >
            <endpoints>
                <endpoint aliasName="incoming" endpointName="Subscriber"/>
                <endpoint aliasName="outgoing" endpointName="Publisher"/>
            </endpoints>
        </xService>
        <xService name="BlobService" type="IPortfolioService" >
            <endpoints>
                <endpoint aliasName="incoming" endpointName="Subscriber"/>
                <endpoint aliasName="outgoing" endpointName="Publisher"/>
            </endpoints>
        </xService>
    </xServices>
</point.Services>
Run Code Online (Sandbox Code Playgroud)

这是我加载它的代码:

public class PointServices : ConfigurationSection
{
    public static PointServices Get()
    {
        var t = (PointServices)ConfigurationManager.GetSection("point.Services/xServices");

        return null;
    }

    //<summary>
    //Declares a collection …
Run Code Online (Sandbox Code Playgroud)

c# configuration app-config configurationsection

5
推荐指数
1
解决办法
1万
查看次数

如何解决"无法识别的元素'elementName'.(第x行)(第x行)"?

我有以下代码

var section = new CustomConfigurationSection();
section.SectionInformation.Type = "System.Configuration.NameValueFileSectionHandler";
section.SectionInformation.SetRawXml(sectionXml);
configuration.Sections.Add(sectionName, section);
Run Code Online (Sandbox Code Playgroud)

最后一行抛出:

ConfigurationErrorsException执行monitor的配置节处理程序时发生错误.

内部异常:

无法识别的元素'屏幕'.(第1行)(第1行)

CustomConfigurationSection的定义:

public class CustomConfigurationSection: ConfigurationSection
{
    public CustomConfigurationSection()
    {
    }
}
Run Code Online (Sandbox Code Playgroud)

configuration是自定义类的实例,它具有名为Sections的属性,其类型为"ConfigurationSectionCollection".

sectionXml中传入的xml是:

<monitor>
  <screens>
    <screen>
      <regions>
        <region>
          <labelCoordinates />
          <startupApplication>Internet</startupApplication>
          <color />
          <width>426</width>
          <height>266</height>
          <x1>0</x1>
          <x2>0</x2>
          <y1>0</y1>
          <y2>0</y2>
        </region>
      </regions>
      <height>800</height>
      <width>1280</width>
    </screen>
    <screen>
      <regions />
      <height>0</height>
      <width>0</width>
    </screen>
  </screens>
</monitor>
Run Code Online (Sandbox Code Playgroud)

我怎样才能让它发挥作用?

c# configurationsection

3
推荐指数
1
解决办法
5116
查看次数