성태의 닷넷 이야기
홈 주인
모아 놓은 자료
프로그래밍
질문/답변
사용자 관리
사용자
메뉴
아티클
외부 아티클
유용한 코드
온라인 기능
MathJax 입력기
최근 덧글
[정성태] Roll A Lisp In C - Reading ; https...
[정성태] Java - How to use the Foreign Funct...
[정성태] 제가 큰 실수를 했군요. ^^; Delegate를 통한 Bein...
[정성태] Working with Rust Libraries from C#...
[정성태] Detecting blocking calls using asyn...
[정성태] 아쉽게도, 커뮤니티는 아니고 개인 블로그입니다. ^^
[정성태] 질문이 잘 이해가 안 됩니다. 우선, 해당 소스코드에서 ILis...
[양승조
] var대신 dinamic으로 선언해서 해결은 했습니다. 맞는 해...
[양승조
] 또 막혔습니다. ㅠㅠ var list = props[i].Ge...
[양승조
] 아. 감사합니다. 어제는 안됐던것 같은데....정신을 차려야겠네...
글쓰기
제목
이름
암호
전자우편
HTML
홈페이지
유형
제니퍼 .NET
닷넷
COM 개체 관련
스크립트
VC++
VS.NET IDE
Windows
Team Foundation Server
디버깅 기술
오류 유형
개발 환경 구성
웹
기타
Linux
Java
DDK
Math
Phone
Graphics
사물인터넷
부모글 보이기/감추기
내용
<div style='display: inline'> <h1 style='font-family: Malgun Gothic, Consolas; font-size: 20pt; color: #006699; text-align: center; font-weight: bold'>ContextBoundObject 상속 클래스와 System.Reflection.ReflectionTypeLoadException 예외</h1> <p> 제목 짓기가 영 난감하군요. ^^<br /> <br /> 암튼, 다음의 간단한 프로그램을 실행하면,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > using System; using System.Reflection; class Program { static void Main(string[] args) { Assembly asm = typeof(Program).Assembly; foreach (Type type in <span style='color: blue; font-weight: bold'>asm.GetTypes()</span>) { Console.WriteLine(type.FullName); } } } <span style='color: blue; font-weight: bold'>class Test<T> : ContextBoundObject { public Test() { } } </span> </pre> <br /> asm.GetTypes 호출 시 예외가 발생합니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > An unhandled exception of type 'System.Reflection.ReflectionTypeLoadException' occurred in mscorlib.dll Additional information: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information. Unhandled Exception: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information. at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module) at System.Reflection.RuntimeModule.GetTypes() at System.Reflection.Assembly.GetTypes() at Program.Main(String[] args) in E:\...\ConsoleApplication1\Program.cs:line 9 </pre> <br /> 재미있는 것은, 저 소스 코드에서 아래의 2가지 변경 사항 중 하나라도 적용하면 예외가 발생하지 않습니다.<br /> <br /> <ul> <li>Test 제네릭 타입을 일반 타입으로 전환한 경우</li> <li>ContextBoundObject 상속을 받지 않는 경우</li> </ul> <br /> 즉, ContextBoundObject이면서 제네릭 타입을 정의한 어셈블리의 GetTypes 호출은 예외가 발생하는 것입니다.<br /> <br /> 이유는 간단합니다. 원래 ContextBoundObject 상속 클래스는 제네릭이어서는 안된다는 간단한 제약이 있기 때문입니다. 실제로 비주얼 스튜디오 디버깅으로 통해 보면 다음과 같은 LoaderExceptions 메시지를 확인할 수 있습니다.<br /> <br /> <img onclick='toggle_img(this)' class='imgView' alt='context_bound_object_reflection_1.png' src='/SysWebRes/bbs/context_bound_object_reflection_1.png' /><br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Generic context-bound objects are not supported. : Test`1 </pre> <br /> 물론 도움말에도 나와 있습니다. ^^<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > ContextBoundObject Class ; <a target='tab' href='https://learn.microsoft.com/en-us/dotnet/api/system.contextboundobject'>https://learn.microsoft.com/en-us/dotnet/api/system.contextboundobject</a> </pre> <br /> <div style='BACKGROUND-COLOR: #ccffcc; padding: 10px 10px 5px 10px; MARGIN: 0px 10px 10px 10px; FONT-FAMILY: Malgun Gothic, Consolas, Verdana; COLOR: #005555'> Notes to Implementers: <br /> <br /> The current version of the common language runtime <span style='color: blue; font-weight: bold'>does not support generic ContextBoundObject types</span> or nongeneric ContextBoundObject types that have generic methods. Attempting to create an instance of such a type causes a TypeLoadException. </div><br /> <br /> 단지, 문제는? 컴파일러로 하여금 이런 클래스를 만드는 것이 문제가 안되고 런타임 시에만 Type Loader에 의해 오류가 발생한다는 점입니다.<br /> <br /> (그나저나... 의도한 것은 아니지만... 다른 프로그램이 GetTypes로 Reflection 열람을 막고 싶다면 이런 클래스를 그냥 정의해 두는 것만으로 효과가 있겠군요. ^^;)<br /> <br /> (<a target='tab' href='http://www.sysnet.pe.kr/bbs/DownloadAttachment.aspx?fid=982&boardid=331301885'>첨부 파일은 이 글의 테스트 코드를 포함</a>합니다.)<br /> </p><br /> <br /><hr /><span style='color: Maroon'>[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]</span> </div>
첨부파일
스팸 방지용 인증 번호
1041
(왼쪽의 숫자를 입력해야 합니다.)