Oracle.ManagedDataAccess.Core - GetTypes 호출 시 "Could not load file or assembly 'System.DirectoryServices.Protocols...'" 오류
Oracle.ManagedDataAccess.Core 2.x 버전에서 GetTypes 메서드 또는 (내부에서 GetTypes 메서드를 호출하는) DefinedTypes 속성을 접근하면,
Assembly asm = typeof(OracleConnection).Assembly;
Type [] types = asm.GetTypes();
// 또는, (내부적으로 GetTypes를 호출하는) DefinedTypes
foreach (Type type in asm.DefinedTypes)
{
Console.WriteLine(type.FullName);
}
이런 예외가 발생합니다.
Unhandled exception. System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Could not load file or assembly 'System.DirectoryServices.Protocols, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.Assembly.GetTypes()
at Program.Main(String[] args) in C:\...\Console1\Console1\Program.cs:line 10
System.IO.FileNotFoundException: Could not load file or assembly 'System.DirectoryServices.Protocols, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
File name: 'System.DirectoryServices.Protocols, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
혹시나 싶어 ReflectionOnlyLoad로 해봤더니,
Assembly reflectionOnlyAsm = Assembly.ReflectionOnlyLoad(asm.FullName);
지원이 안 되는군요. ^^
Unhandled exception. System.PlatformNotSupportedException: ReflectionOnly loading is not supported on this platform.
at System.Reflection.Assembly.ReflectionOnlyLoad(String assemblyString)
at Program.Main(String[] args) in C:\...\Console1\Console1\Program.cs:line 13
어쩔 수 없습니다. 예외 메시지 그대로 "System.DirectoryServices.Protocols" 어셈블리 참조를 nuget으로부터 추가하면 됩니다. 혹은, 최근에 나온 3.x 버전의 Oracle.ManagedDataAccess.Core 패키지로 업그레이드해도 해결이 됩니다.
[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]