이것은 생각의 길을 따라 도움이 될 수 있습니다. "또는 런타임 DLL 로딩 메커니즘에 디렉토리를 추가 할 수 있습니다.NET 그렇게 그 Matlab 코어 dll을 올바르게 컴퓨터를 다시 시작하지 않고 참조 할 수 있습니다 ":
하나의 응용 프로그램에서 나는 .NET에 어셈블리를 찾을 때 다음 코드를 사용하여 동적으로로드하려고 할 때. 제 경우에는 이 내 애플 리케이션은 다른 프로그램의 확장으로로드되므로 내 DLL은 응용 프로그램 exe와 같은 디렉토리에 있지 않습니다.
제 경우 내 주요 응용 프로그램 DLL이 올바르게로드되고, COM interop에 등록되어 있기 때문에 .NET Enterprise 라이브러리가 어셈블리를로드하기 위해서는 다음과 같은 작업을 수행해야합니다. 다음과 같은 코드는 .NET에서 현재 실행중인 것을 확인합니다. 어셈블리를 찾을 때 어셈블리의 디렉토리 하중. .NET에서 볼 수있는 모든 디렉토리에서 동일한 작업을 수행 할 수 있습니다 (예 :. 환경 변수에 기초한 것들.
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.IO;
namespace CommonClasses
{
/// <summary>
/// Helper class to ensure the Common Language Runtime can dynamically load our referenced dlls.
/// Because our components are called from COM via iexplore.exe the executing directory is likely to be something like
/// c:\program files\internet explorer\, which obviously doesn't contain our assemblies. This only seems to be a problem
/// with the Enterprise Library so far, because it dynamically loads the assemblies it needs.
/// This class helps by directing the CLR to use the directory of this assembly when it can't find the assembly
/// normally. The directory of this assembly is likely to be something like c:\program files\my program\
/// and will contain all the dlls you could ask for.
/// </summary>
public static class AssemblyResolveAssistant
{
/// <summary>
/// Records whether the AssemblyResolve event has been wired.
/// </summary>
private static bool _isWired = false;
/// <summary>
/// Add the handler to enable assemblies to be loaded from this assembly's directory, if it hasn't
/// already been added.
/// </summary>
public static void AddAssemblyResolveHandler()
{
if (!_isWired)
{
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
_isWired = true;
}
}
/// <summary>
/// Event handler that's called when the CLR tries to load an assembly and fails.
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
/// <returns></returns>
static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
Assembly result = null;
// Get the directory where we think the assembly can be loaded from.
string dirName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
AssemblyName assemblyName = new AssemblyName(args.Name);
assemblyName.CodeBase = dirName;
try
{
//Load the assembly from the specified path.
result = Assembly.Load(assemblyName);
}
catch (Exception) { }
//Return the loaded assembly, or null if assembly resolution failed.
return result;
}
}
}
그런 다음 일반 폴더 외부 어셈블리의 로딩이 필요합니다 아무것도하기 전에 방법 AssemblyResolveAssistant.AddAssemblyResolveHandler()
를 호출합니다.
사용자는 현재 컴퓨터를 다시 시작해야합니다. 어쩌면 나중에 제공된 답변 중 일부를 시도 할 시간이 있습니다. – pauloya
더 이상 컴퓨터를 다시 시작할 필요가 없습니다. 서비스가 시작되고 Matlab DLL이 성공적으로로드되면 System.Environment.SetEnvironmentVariable()을 사용하여 Path 변수를 변경합니다. – pauloya