1
votes

The type initializer for 'MathWorks.MATLAB.NET.Utility.MWMCR' threw an exception:

I am calling from c#, a function in my DLL compiled by MatLab Library Compiler.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using MathWorks.MATLAB.NET.Arrays;
using MathWorks.MATLAB.NET.Utility;
using AddVidToDB;

namespace AddToDb
{
    class Program
    {
        static void Main(string[] args)
        {
            Class1 obj = null;
            // MWNumericArray input = null;
            MWNumericArray output = null;
            MWArray[] result = null;
            MWArray input = null;

            try
            {
                // Instantiate your component class.
                obj = new Class1();

                // Invoke your component.
                string VidName = "080626439d8809181a1857685bdc645.mp4";
                input[0] = VidName;
                obj.AddVidToDB(input);
            }
            catch
            {
                throw;
            }
        }
    }
}

When I run the code, it gives an exception:

"The type initializer for 'AddVidToDB.Class1' threw an exception.". The inner exception says: "The type initializer for 'MathWorks.MATLAB.NET.Utility.MWMCR' threw an exception.".

Stack trace says:

at AddVidToDB.Class1..ctor() at AddToDb.Program.Main(String[] args) in d:\MSc\Project\SurfSearchVid\AddToDb\AddToDb\AddToDb\Program.cs:line 40 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()

So how do I fix this?

1

1 Answers

1
votes

You must to have Runtime Library installed on you computer to call MCR dll's. If you have it check that the PATH (environment variables) contains the runtime path. You can check if the user that run the code have the correct path variable using:

Environment.GetEnvironmentVariable("Path");

The variable must contains something like this:

C:\Program Files\MATLAB\MATLAB Compiler Runtime\v79\runtime\{win32|win64};