2012-09-07 4 views
0

C# Visual Studio 2010에서 DLL 응용 프로그램 설정을 읽는 데 문제가 있습니다. ConfigurationManager가 실패하여 리플렉션을 사용하여 get workarounded의 샘플 코드를 게시합니다.DLL app.setting에서 문제가 발생했습니다.

private string LDAPDomain 
{ 
    get 
    { 
     string strPath = System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName; 
     string val = GetValues(strPath, "LDAPDomain"); 
     return val; 
    } 
} 


//strPath is path of the file. 
//strKey is key to access 

private string GetValues(string strPath, string strKey) 
{ 
    System.Configuration.Configuration con = System.Configuration.ConfigurationManager.OpenExeConfiguration(strPath); 
    string strValue = con.AppSettings.Settings[strKey].Value; 

    return strValue; 
} 

답변

2

DLL을 참조하는 기본 프로젝트가 앱 설정을 선택하기를 기대한다면 그렇게 작동하지 않습니다. ConfigurationManager은 실행중인 어셈블리의 구성을 읽을 것이므로이를 사용하려면 응용 프로그램에 필요한 모든 구성을 넣어야합니다.

또는 수 있습니다.은 DLL의 app.config 파일 내용을 읽습니다. 일부 예제 코드는 this question을 참조하십시오.

+0

문제를 해결하지 못했습니다. –

+0

@SimoneSpagna 일부 컨텍스트가 도움이 될 것입니다 ... – James