해결하려고하는 문제를 데모하기 위해 작은 테스트 앱을 만들었습니다. 플러그인이 인터페이스에서 파생되는 플러그인 아키텍처가 있습니다.요청한 유형 중 하나 이상을로드 할 수 없습니다. loaderexceptions를 검색하십시오.
namespace Test
{
public interface ITestBase
{
int LifeTheUniverseAndEverything();
bool Pessimist();
bool Optimist();
}
}
이 주 프로그램 솔루션 및 플러그인 솔루션을 참조하는 .DLL에 빌드 :
여기 인터페이스 코드입니다.
namespace Test
{
public class TestPlugin : ITestBase
{
public int LifeTheUniverseAndEverything() { return 41; }
public bool Pessimist() { return false; }
public bool Optimist() { return true; }
}
}
이는 "플러그인"주요 작업 디렉토리를 폴더를 삭제하는 .DLL을 생산 : 여기
플러그인 코드입니다.다음은 주요 프로그램입니다. 요청 된 유형 중 하나 이상을로드 할 수 없습니다 :
namespace Test
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("testing...");
string[] PluginFileLocs;
try
{
string sWorkingDir = Directory.GetCurrentDirectory();
string sPluginDir = sWorkingDir + "\\Plugins";
PluginFileLocs = Directory.GetFiles(sPluginDir, "*.dll");
foreach (string plugin in PluginFileLocs)
{
Assembly theAssembly = Assembly.ReflectionOnlyLoadFrom(plugin);
foreach (Type type in theAssembly.GetTypes())
{
string aType = type.FullName;
Console.WriteLine(aType);
}
}
}
catch (Exception e)
{
Console.WriteLine("Error: " + e.Message);
}
}
}
}
문제는 testplugin 클래스는 ITestBase 인터페이스를 파생 경우 theAssembly.GetTypes에서 예외가 발생한다는 것이다. LoaderExceptions를 검색하십시오. 왜, 어떻게 플러그인에서 인터페이스를 파생시킬 수 있습니까?
그래서'ReflectionTypeLoadException'을 얻게 될 것입니다. 메시지에서 확인하라고하는 로더 예외는 무엇입니까? 예외에는'LoaderExceptions'라는 속성이 있습니다. http://msdn.microsoft.com/en-us/library/system.reflection.reflectiontypeloadexception.loaderexceptions.aspx – vcsjones