1

したがって、app-config ファイルを使用するのはまったく初めてで、同じキーから複数の値を読み取ることができるようにカスタム構成ハンドラーを作成しようとしています。Microsoft Web サイトのドキュメントに従いましたが、問題が発生しました。

コードを実行しようとするたびに、このエラーがスローされます

「認識されない属性 'datatype'。属性名は大文字と小文字が区別されることに注意してください。(C:\Users\stephen.carmody\Desktop\FlatFileFactory - Copy\FlatFileFactory\bin\Debug\FlatFileFactory.vshost.exe.Config 行 21)」

要素の最初の 2 つの値のみを認識しているようで、3 番目の「データ型」がエラーをスローします。

ここに私の設定ファイルがあります

 <?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <!-- Configuration section-handler declaration area. -->
 <configSections>
  <sectionGroup name="propertyValuesGroup">
  <section
    name="propertyValues"
    type="FlatFileTestCaseAutomater.CustomConfigurationSectionHandler,FlatFileFactory"
    allowLocation="true"
    allowDefinition="Everywhere"
  />
</sectionGroup>
<!-- Other <section> and <sectionGroup> elements. -->
</configSections>

<!-- Configuration section settings area. -->


<propertyValuesGroup>
<propertyValues>
  <cHeaderProperty name="txnNo" nullable="yes" datatype="int" maxlength="" />
</propertyValues>
</propertyValuesGroup>

</configuration>

これが私のカスタムハンドラークラスです:

namespace FlatFileTestCaseAutomater
{
    class CustomConfigurationSectionHandler : ConfigurationSection
    {
        [ConfigurationProperty("cHeaderProperty")]
        public CHeaderPropertyElement Property
    {
        get
        {
            return (CHeaderPropertyElement)this["cHeaderProperty"];
        }
        set
        { this["cHeaderProperty"] = value; }
    }
}


public class ClaimHeaderElement : ConfigurationElement
{
    [ConfigurationProperty("name", DefaultValue = "", IsRequired = true)]
    [StringValidator(InvalidCharacters = "~!@#$%^&*()[]{}/;'\"|\\", MinLength = 1, MaxLength = 60)]
    public String Name
    {
        get
        {
            return (String)this["name"];
        }
        set
        {
            this["name"] = value;
        }
    }

    [ConfigurationProperty("dataType", DefaultValue = "", IsRequired = true)]
    [StringValidator(InvalidCharacters = "~!@#$%^&*()[]{}/;'\"|\\", MinLength = 1, MaxLength = 60)]
    public String DataType
    {
        get
        {
            return (String)this["dataType"];
        }
        set
        {
            this["dataType"] = value;
        }
    }

    [ConfigurationProperty("maxLength", DefaultValue = int.MaxValue, IsRequired = false)]
   // [IntegerValidator(ExcludeRange = false, MaxValue = 24, MinValue = 0)]
    public int MaxLength
    {
        get
        { return (int)this["maxLength"]; }
        set
        { this["maxLength"] = value; }
    }

}

}

デバッグ中にブレークが発生するコードのスニペットを次に示します。

  FlatFileTestCaseAutomater.CustomConfigurationSectionHandler config =
    (FlatFileTestCaseAutomater.CustomConfigurationSectionHandler)System.Configuration.ConfigurationManager.GetSection(
    "propertyValuesGroup/propertyValues");

同様のスレッドが以前に投稿されたことは知っていますが、何時間もこれに取り組んできましたが、運がありません

4

1 に答える 1

0

私は間違っているかもしれませんが、構成内の名前は同じ「大文字と小文字」のようには見えません。それらはすべて小文字 (データ型と最大長) で、ここに貼り付けるときのタイプミスですか?

属性は実際に大文字と小文字が区別されます-(コードに基づいて)そうあるべきです

<cHeaderProperty name="txnNo" nullable="yes" dataType="int" maxLength="" />
于 2013-04-25T18:59:04.677 に答える