変更を保存したい ASP.NET 4.0 で実行されているカスタム構成セクションがあります。関連するクラスは次のとおりです。
- QueueConfiguration: ConfigurationElement
- QueueCollection Queues // 維持するキューのリスト
- QueueCollection: ConfigurationElementCollection
- キュー: ConfigurationElement
これは機能します:
// This is a test case to ensure the basics work
Queue newQueue = new Queue();
QueueCollection queues = new QueueCollection();
queues.Add(newQueue); // queues.Count is incremented here
これは機能しません (そしてエラーをスローしません):
// Read existing QueueConfiguration
Queue newQueue = new Queue();
QueueConfiguration queueConfig = ConfigurationManager.GetSection("Queuing") as QueueConfiguration;
queueConfig.Queues.Add(newQueue); // queues.Count is NOT incremented here
これも機能しません (エラーは発生しません):
// Load QueueConfiguration from web.config
Queue newQueue = new Queue();
Configuration config = WebConfigurationManager.OpenWebConfiguration("~");
QueueConfiguration queueConfig = config.GetSection("Queuing") as QueueConfiguration;
queueConfig.Queues.Add(newQueue); // queues.Count is NOT incremented here
私が最初に確認したのは、3 つの構成セクションのうちの 1 つが読み取り専用としてマークされていたことです。ただし、デバッグすると、IsReadOnly() メソッドは QueueConfiguration および QueueCollection インスタンスに対して false を返します。
私の QueueCollection クラスには、次のスニペットが含まれています。
public void Add(Queue queue)
{
base.BaseAdd(queue, true);
}
コードをステップ実行すると、この行に到達し、base.BaseAdd が呼び出されますが、Count プロパティはインクリメントされません。あたかも BaseAdd が単に要求を無視するかのようです。
助言がありますか?(明らかな何かが欠けていることを願っています!)