문제

컴퓨터에 MATLAB 런타임을 설치 한 다음 MATLAB 런타임에서 메소드를 호출하는 .NET Windows 서비스를 다시 시작합니다.
문제는 Windows를 다시 시작할 때까지 TypeInitializationException 오류를 받는다는 것입니다. 우리는 이런 일이 일어나고 있다고 생각합니다 환경 변수는 재시작 할 때까지 서비스에서 변경되지 않습니다 MATLAB은 % 경로 % 변수를 사용하여 코어 DLL을 참조합니다.
내 질문은, 엔진의 코어 DLL을 참조 할 때 MATLAB을 사용할 수 있도록 % PATH % 변수를 변경할 수 있다고 생각합니까?
아니면 런타임 DLL로드 메커니즘에 디렉토리를 추가하여 Matlab Core DLL이 시스템을 다시 시작하지 않고 올바르게 참조되도록 할 수 있습니까?

우리가 얻는 예외는 다음과 같습니다

System.TypeInitializationException: The type initializer for 'MatlabCalculation.Calculation' threw an exception. ---> System.TypeInitializationException: The type initializer for 'MathWorks.MATLAB.NET.Utility.MWMCR' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'mclmcrrt710.dll': Kan opgegeven module niet vinden. (Exception from HRESULT: 0x8007007E)
   at MathWorks.MATLAB.NET.Utility.MWMCR.mclmcrInitialize()
   at MathWorks.MATLAB.NET.Utility.MWMCR..cctor()
   --- End of inner exception stack trace ---
   at MatlabCalculation.Calculation..cctor()
   --- End of inner exception stack trace ---
   at MatlabCalculation.Calculation.Finalize()

"Kan Opgegeven Module Niet Vinden"= "지정된 모듈을 찾을 수 없습니다"

도움이 되었습니까?

해결책

서비스를 다시 작성할 수 있으면 시스템. 환경.NET Code 내에서 .getEnvironmentVariable 및 setEnvironmentVariable 메소드를 직접 추가하십시오. 서비스를 다시 작성할 수 없으면 시도해 볼 수 있습니다. 순 정지/NET 시작 또는 installUtil, 서비스에 따라 행동합니다. 또는 ServerFault에서 물어볼 수도 있습니다.

오래된 대답 질문을 오해했기 때문에 다음과 같습니다.

MATLAB 구성 요소가 시작한 다음 예외를 던지고 있습니까? 그렇다면 CTFroot, ToolboxDir 및 AddPath 기능이 도움이 될 수 있습니다. 아마도 :

if isdeployed
    addpath(ctfroot);
    addpath(toolboxdir('signal'));
    %more addpath(toolboxdir('toolboxname')) statements
end

그러나 Matlab이 전혀 시작되지 않으면 이것이 도움이되지 않습니다.

다른 팁

이것은 당신의 사고 라인을 따라 도움이 될 수 있습니다. "또는 런타임 DLL로드 메커니즘에 디렉토리를 추가하여 Matlab Core DLL이 기계를 다시 시작하지 않고 올바르게 참조되도록 할 수 있습니다.":

하나의 앱에서는 다음 코드를 사용하여 .NET에 동적으로로드하려고 할 때 어셈블리를 찾을 위치를 알려줍니다. 내 경우에는 내 앱이 다른 프로그램으로의 확장으로로드되므로 DLL이 응용 프로그램 exe와 동일한 디렉토리에 있지 않기 때문에이 문제가 필요합니다. 아마도 이것은 당신에게도 적용됩니까?

이 경우 COM Interop에 등록되어 있기 때문에 내 기본 응용 프로그램 DLL이 올바르게로드됩니다. 그러나 MS Enterprise Library가 어셈블리를로드하려면 다음을 수행해야합니다. 다음 코드는 .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() 일반 폴더 외부에 어셈블리를로드 해야하는 작업을 수행하기 전에.

에서: http://www.mathworks.com/support/solutions/en/data/1-a1a70v/index.html?product=mn&solution=1-a70v

해결책:웹 애플리케이션이 CreateEenvironmentBlock 함수를 호출하여 Microsoft Windows Server 2003 기반 또는 Microsoft Windows XP 기반 컴퓨터에서 환경 변수를 검색 할 때, 반환 된 경로 환경 변수는 1,024 바이트로 잘린다. 이 동작은 환경 변수의 최대 크기가 2,048 바이트이지만 발생합니다. 이 문제는 웹 응용 프로그램이 올바른 환경 변수를 얻지 못하게합니다.

구체적으로, 경로의 MATLAB 컴파일러 런타임 디렉토리는 반환 된 경로 환경 변수에서 잘릴 수 있습니다.

문제를 해결하려면 다음 중 하나를 수행하십시오.

1) 기존 경로 변수의 시작 부분에 MATLAB 컴파일러 런타임 디렉토리를 추가하십시오.

2) 다음 Microsoft 웹 사이트 에서이 문제에 대한 패치를 얻으십시오.http://support.microsoft.com/kb/906469

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top