문자열에서 클래스 유형을 가져 오려고합니다. 나는 이것에 대해 먼 길을 갈 수 느끼지만, 이것은 내가 지금까지 가지고있는 코드 :주어진 유형의 어셈블리를 만들기위한 리플렉션
A first chance exception of type 'System.IO.FileLoadException' occurred in mscorlib.dll
그래서 이미 조립이 있습니다
이System.Reflection.MethodInfo method = typeof(MyClass).GetMethod("MyFunc");
string myInterfaceId = "ITest";
Type myType = _type; // This is a WPF App that ultimately calls this process
// Debugger shows that _is correctly populated
AssemblyName an = new AssemblyName(myType.AssemblyQualifiedName); // Error here
Assembly a = Assembly.Load(an);
System.Reflection.MethodInfo generic = method.MakeGenericMethod(
a.GetType(myInterfaceId))
내가 오류입니다 오류가 발생한 지점의 메모리. 리플렉션을 사용하여 이미 메모리에있는 어셈블리를로드 할 수 있습니까? Assembly.Load(...
을 사용하지 않고 리플렉션을로드하는 방법이 있습니까?
이 편집 :
덕분에 제안을 @stakx하기 위해, 나는 마침내이 함께했다 :
var meInterfaceType = myType.GetTypeInfo().Assembly.DefinedTypes.FirstOrDefault(k => k.Name == myInterfaceId)
작동하지 않는 코드를 볼 수 있습니다. 그러나 실제로 무엇을하고 싶습니까? 왜 그 어셈블리를로드하고 싶습니까? 너는 그걸로 무엇을 할거니? 그것은 당신이 말한 것처럼 이미 우회를하고있을 수도 있으므로 이상적으로 우리는 당신이 우회로가는 것이 아니라 가장 쉬운 방법으로 목표를 달성하도록 도울 것입니다. – stakx