DLL 프로젝트에서 종속된 DLL들을 로드를 할때 프로그래밍적으로 종속된 DLL의 path를 변경해야될
경우가 있었다. 아래 코드는 프로그래밍적으로 종속된 DLL들의 path를 변경해준다
public void test()
{
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.AssemblyResolve += new ResolveEventHandler(MyResolveEventHandler);
}
private Assembly MyResolveEventHandler(object sender, ResolveEventArgs args)
{
//This handler is called only when the common language runtime tries to bind to the assembly and fails.
//Retrieve the list of referenced assemblies in an array of AssemblyName.
Assembly MyAssembly, objExecutingAssembly;
string strTempAssmbPath = "";
objExecutingAssembly = Assembly.GetExecutingAssembly();
AssemblyName[] arrReferencedAssmbNames = objExecutingAssembly.GetReferencedAssemblies();
//Loop through the array of referenced assembly names.
foreach(AssemblyName strAssmbName in arrReferencedAssmbNames)
{
//Check for the assembly names that have raised the "AssemblyResolve" event.
if(strAssmbName.FullName.Substring(0, strAssmbName.FullName.IndexOf(",")) == args.Name.Substring(0, args.Name.IndexOf(",")))
{
//Build the path of the assembly from where it has to be loaded.
strTempAssmbPath = "C:\\Myassemblies\\" + args.Name.Substring(0,args.Name.IndexOf(","))+".dll";
break;
}
}
//Load the assembly from the specified path.
MyAssembly = Assembly.LoadFrom(strTempAssmbPath);
//Return the loaded assembly.
return MyAssembly;
}
[참고자료]
'개발지식창고 > C#' 카테고리의 다른 글
How to select multiple controls by mouse-dragging over them (0) | 2022.02.23 |
---|---|
COM+ 생성방법 (0) | 2015.02.25 |
COM+ 컴포넌트 멀티쓰레드 실행을 위한 IIS설정 (0) | 2015.02.14 |
.net Framework Error (HRESULT 0x8007000B) (0) | 2015.02.11 |
C#에서 DebugView 사용하기 (0) | 2015.02.02 |