C : \ MyApp에있는 콘솔 앱이 있습니다.C#, Activator.CreateInstance (assemblyType) 객체가 참조하는 DLL 가져 오기
저는 앱에서 참조하지 않는 여러 라이브러리가 있습니다. Activator.CreateInstance()를 사용하여 사용합니다. 그들은 C : \ MyLibrary \ Job001, C : \ MyLibrary \ Job002 등에 있습니다. 이 라이브러리들 각각은 다중 의존성을 가지며, 주 앱에 이미 존재하는 서로 다른 버전의 의존성 일 수 있습니다.
실행하려고하면이 오류가 표시됩니다. Could not load file or assembly 'Persistence.Database, Version=1.7.2.67, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
이것은 대부분의 작업에 공통적 인 종속성 중 하나입니다. 디렉토리를 확인했는데 라이브러리가 존재합니다.
및 라이브러리를 활성화하려면 어떻게합니까? 해당 디렉토리에있는 참조를 사용합니까? 나는 도서관을 활성화하기 위해 다음 (확장) 코드를 사용하고
: 나는 system.appdomain.assemblyresolve에서 찾고 있지만 라이브러리 프로젝트에서 이것을 사용하는 방법을 의 감각을하고 있지 않다
public static IJob ConcreteJob(this JobInfoPayload src)
{
if (src.AssemblyFile.IsNullOrEmpty())
throw new Exception("AssemblyFile cannot be empty or null!");
if (src.AssemblyName.IsNullOrEmpty())
throw new Exception("AssemblyName cannot be empty or null!");
try
{
var assembly = Assembly.LoadFile(src.AssemblyFile);
var assemblyType = assembly.GetType(src.AssemblyName);
var job = Activator.CreateInstance(assemblyType) as IJob;
return job;
}
catch (Exception ex)
{
Serilog.Log.Logger.Fatal(ex, "JOB was not able to be created!!");
throw; // bubble this up to the top...
}
}
.
생각하십니까?
추가 정보 (2016 11월 29일)
서버 응용 프로그램 참조 :
- Library.Infrastructure
- QueueApp.Core
- Hangfire
- OWIN
작업 라이브러리 참조 :
- Library.Infrastructure
- Library.Persistence
- Library.SQL.Database01
- Library.SQL.Database02
- QueueApp.Job .Core (210)
- EntityFramework는
우리는 몇 가지 채용 하지만가 작업 도서관의 다른 버전을 참고로 구축 할 수있는 동일한 패턴을 따르는 있습니다. 이것은 시간이 지남에 따라 느린 크리프가 원인입니다. 작년에 작성된 작업이 여전히 작동하는 경우 왜 솔루션을 열어 모든 참조를 업데이트하고 다시 컴파일 한 다음 QA 및 승인을 거쳐 한 달을 보내면 그냥 두어도됩니까?
내가 겪고있는 도전 과제는 참조 된 파일을 찾을 수 없어서 서버 응용 프로그램 디렉토리에 있어야한다는 것입니다. 대신 그들은 그 욥의 디렉토리에 있습니다. Fuslogvw.exe를 사용하면 DLL의 디렉토리가 아니라 호스팅하는 응용 프로그램의 디렉토리가 표시됩니다.
** Assembly.LoadFrom() 또는 Assembly.LoadFile()을 사용하는지 여부에 관계없이 현재 동일한 문제가 발생합니다.
FUSLOGVW 로그 결과 :
D : 응용 프로그램이 모든 파일을 찾고
*** Assembly Binder Log Entry (11/29/2016 @ 10:20:21 AM) ***
The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable D:\Dev\QueueApp\Source\QueueApp\bin\Debug\QueueApp.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: DisplayName = Job.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null (Fully-specified)
LOG: Appbase = file:///D:/Dev/QueueApp/Source/QueueApp/bin/Debug/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = QueueApp.exe
Calling assembly : Job.AgileExport, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: D:\Dev\QueueApp\Source\QueueApp\bin\Debug\QueueApp.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///D:/Dev/QueueApp/Source/QueueApp/bin/Debug/Job.Core.DLL.
LOG: Attempting download of new URL file:///D:/Dev/QueueApp/Source/QueueApp/bin/Debug/Job.Core/Job.Core.DLL.
LOG: Attempting download of new URL file:///D:/Dev/QueueApp/Source/QueueApp/bin/Debug/Job.Core.EXE.
LOG: Attempting download of new URL file:///D:/Dev/QueueApp/Source/QueueApp/bin/Debug/Job.Core/Job.Core.EXE.
LOG: All probing URLs attempted and failed.
을 \ 데브 \ QueueApp \ 소스 \ QueueApp \ 빈 \ 디버그
작업이 존재 :
를 D : \ Dev \ QueueApp \ Source \ Job.AgileExport \ bin \ Debug
결코 절대로 LoadFile()을 사용하지 마십시오. 항상 LoadFrom()을 사용하지 마십시오. 그래도 문제가 지속되면 Fuslogvw.exe –
을 LoadFrom()으로 전환해도 여전히 같은 오류가 발생합니다. (위의 추가 정보 참조) –
다른 어셈블리를로드하고 사용할 수 있습니까? – McNets