문제

최근에 Vista X64로 올라갔습니다. 갑자기 Machine.Config AppSettings 블록은 .NET 어셈블리에서 읽지 않습니다.

구성 직후 및 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>

메모장 ++를 관리자로 실행하여 저장해야했습니다. 왜냐하면 아마도 좋은 이유가 있기 때문입니다. 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()
---

내가 쓰는 앱은 machine.config를 사용하여 app.config에서 찾을 수없는 경우 사용자가 어떤 환경을 실행 해야하는지 알아 내기 위해 폴백으로 사용하므로 앱을 다시 작성하여 알아 내지 않아도됩니다. 2000 년과 XP와 동일하게 작동 해야하는 것.

도움이 되었습니까?

해결책

다음 코드 줄로 해결했습니다.

ConfigurationManager.OpenMachineConfiguration().FilePath

반품 :

C:\Windows\Microsoft.NET\Framework64\v2.0.50727\Config\machine.config

대신에:

C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config

지금 64 비트를 사용하고있는 것을 잊었습니다. 적절한 구성 파일에 AppSettings 섹션을 추가하면 문제가 해결되었습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top