最近、Vista x64 に移行したところ、突然、machine.config appSettings ブロックが .NET アセンブリによって読み取られなくなりました。
configSections の直後、および C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config の configProtectedData の前に、次のものがあります。
<appSettings>
<add key="foo" value="blah"/>
</appSettings>
<system.runtime.remoting>
<customErrors mode="Off"/>
</system.runtime.remoting>
おそらく正当な理由でロックされているため、管理者としてNotepad ++を実行して保存する必要がありました。SnippetCompiler または VS .NET 2008 で次のコードを実行します。
foreach(var s in ConfigurationManager.AppSettings.AllKeys)
{
Console.WriteLine(s);
}
AppSettingsReader asr = new AppSettingsReader();
Console.WriteLine(asr.GetValue("foo", typeof(string)));
キーを書き出さず、次の例外で失敗します。
---
The following error occurred while executing the snippet:
System.InvalidOperationException: The key 'foo' does not exist in the appSettings configuration section.
at System.Configuration.AppSettingsReader.GetValue(String key, Type type)
at MyClass.RunSnippet()
at MyClass.Main()
---
私が作成したアプリは、app.config で見つからない場合に、ユーザーが実行している環境を見つけるためのフォールバックとして machine.config を使用するため、アプリを書き直して把握する必要は避けたいと考えています。 2000 や XP と同じように動作するはずです。