몇 가지 속성이있는 정적 클래스 Utils가 포함 된 클래스 라이브러리가 있습니다.C에서 초기화 이니셜 라이저 예외
Utils 클래스의 속성 중 하나를 내 콘솔 응용 프로그램으로 호출하면이 오류가 발생합니다. 다음은 Utils 클래스의 작은 샘플입니다.
public static class Utils
{
public static int CurrentEmpId = -1;
public static int CurrentUserId
{
get
{
if (HttpContext.Current != null)
{
if(HttpContext.Current.Session["CurrentUserId"] == null)
{
HttpContext.Current.Session["CurrentUserId"] = GetCurrentUser();
return Int32.Parse(HttpContext.Current.Session["CurrentUserId"]);
}
else
{
return Int32.Parse(HttpContext.Current.Session["CurrentUserId"]);
}
}
return -1;
}
}
//this is making call to a static Method in a static Class called _
public static string RowHeader = _.T("Some Header");
}
내가 콘솔 응용 프로그램에서 CurrentUserId 속성을 사용하려고하면 예외가 발생합니다. 나는 public static string RowHeader = _.T ("Some Header")를 주석 처리했다. 코드 및 예외가 사라졌습니다. 어느 경우 든 컴파일러가 없거나 오류가 발생합니다.
은 "_"라는 이름의 클래스가 몇 가지 수정이 하나입니다 Translation Class
내 질문이 CurrentUserId 재산이 이유 때문에 행 헤더 하나의 예외가 발생입니까?
관련 질문과 같은 여러 유사한 질문이없는 좋은 이유를 제공해주십시오. http://stackoverflow.com/questions/1226188/c-sharp-error-the-type-initializer-for-threw-an - 예외? rq = 1? (정적 생성자/파일 초기화 메소드가 전체 타입을 초기화하는 데 실패한 경우 –
"약간의 수정"이 중요 할 수 있습니다 ... – Dunken
@Dunken 수정 사항은 클래스의 이름 변경이며 정적으로 변경됩니다. 왜 충돌을 일으키는 지 확신 할 수 없습니다. – Aleks