カスタム構成セクションの原因を突き止めるために数時間を費やしましたが、問題の根本を見つけることができません。構成セクションの設定が初期化されていません
私はエラーを取得しています:
設定CS
public class TankConfigurationSection : ConfigurationSection
{
[ConfigurationProperty("afServer", IsRequired = true)]
[StringValidator(InvalidCharacters = "[email protected]#$%^&*()[]{}/;'\"|\\", MinLength = 0, MaxLength = 60)]
public String AfServer
{
get
{
return (String)this["afServer"];
}
set
{
this["afServer"] = value;
}
}
[ConfigurationProperty("afDatabase", IsRequired = true)]
[StringValidator(InvalidCharacters = "[email protected]#$%^&*()[]{}/;'\"|\\", MinLength = 1, MaxLength = 60)]
public String AfDatabase
{
get
{
return (String)this["afDatabase"];
}
set
{
this["afDatabase"] = value;
}
}
[ConfigurationProperty("tankTemplate", IsRequired = true)]
[StringValidator(InvalidCharacters = "[email protected]#$%^&*()[]{}/;'\"|\\", MinLength = 1, MaxLength = 60)]
public String TankTemplate
{
get
{
return (String)this["tankTemplate"];
}
set
{
this["tankTemplate"] = value;
}
}
}
を:
An exception of type 'System.Configuration.ConfigurationErrorsException' occurred in System.Configuration.dll but was not handled in user code
Additional information: The value for the property 'afDatabase' is not valid. The error is: The string must be at least 1 characters long.
は私の構成セクションを見て、私は私がString Validatorが設定されていることを注目してスタートを切りました
afServerで1文字長のString Validator要件を削除し、afDatabaseでエラーが発生したことに気付きました。値が決して初期化されていないように見えるので、afServerの最小長が1の場合は失敗しますが、それを削除するとafDatabaseにエラーが発生します。私はガイドとしてこれを使用してきた
<configuration>
<!-- Configuration section-handler declaration area. -->
<configSections>
<sectionGroup name="tankConfigurationGroup">
<section
name="tankConfiguration"
type="TankInventory.Configurations.TankConfigurationSection"
allowLocation="true"
allowDefinition="Everywhere"
/>
</sectionGroup>
<!-- Other <section> and <sectionGroup> elements. -->
</configSections>
<!-- Configuration section settings area. -->
<tankConfigurationGroup>
<tankConfiguration afServer ="Test123" afDatabase ="Test123" tankTemplate ="Test21345" >
</tankConfiguration>
</tankConfigurationGroup>
</configuration>
:ここ
は私の のweb.configある https://msdn.microsoft.com/en-us/library/2tw134k3.aspx
?価値を得ようとしているのか、それとも実行時だけですか? –
実行時に - アプリケーションを実行するたびに発生します。 – user44036