.Net 3.5 콘솔 애플리케이션을 vs2008에서 vs2017 (대상 프레임 워크 netcoreapp1.1)의 .Net Core 콘솔 애플리케이션으로 포팅하고 있습니다.
프로그램은 주어진 디렉토리에서 .dll을 찾고 어셈블리로로드하여 플러그인로드를 수행합니다.
플러그인을 netstandard1.6 라이브러리로 다시 빌드했습니다. 솔직히 Core, Framework 및 Standard의 차이점에 약간 혼란스러워합니다.
System.Runtime.Loader (v4.3.0) NuGet 패키지와 다음 코드를 사용하여 지정된 경로에서 어셈블리를로드하려고합니다.
public static Assembly LoadAssemblyFromPath(string path)
{
AssemblyLoadContext.Default.Resolving += (context, name) =>
{
// avoid loading *.resources dlls, because of: https://github.com/dotnet/coreclr/issues/8416
if (name.Name.EndsWith("resources"))
return null;
string[] foundDlls =
Directory.GetFileSystemEntries(new FileInfo(path).FullName, name.Name + ".dll", SearchOption.AllDirectories);
return foundDlls.Any() ? context.LoadFromAssemblyPath(foundDlls[0]) : context.LoadFromAssemblyName(name);
};
return AssemblyLoadContext.Default.LoadFromAssemblyPath(path);
}
경로 매개 변수가 올바른지 확인했으며 파일이 존재하지만 여전히 "파일 또는 어셈블리를로드 할 수 없습니다"예외가 발생합니다. Resolving 이벤트는 발생하지 않습니다.
누구든지 내가 뭘 잘못하고 있는지에 대한 통찰력을 줄 수 있습니까?
나는 다음을 사용하게되었다.
public static Assembly LoadAssemblyFromPath(string path)
{
string fileNameWithOutExtension = Path.GetFileNameWithoutExtension(path);
bool inCompileLibraries = DependencyContext.Default.CompileLibraries.Any(l => l.Name.Equals(fileNameWithOutExtension, StringComparison.OrdinalIgnoreCase));
bool inRuntimeLibraries = DependencyContext.Default.RuntimeLibraries.Any(l => l.Name.Equals(fileNameWithOutExtension, StringComparison.OrdinalIgnoreCase));
return inCompileLibraries || inRuntimeLibraries
? Assembly.Load(new AssemblyName(fileNameWithOutExtension))
: AssemblyLoadContext.Default.LoadFromAssemblyPath(path);
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다