title: matlab code on IIS not working
body: <p>I am using VS2013, Matlab 2015Ra, and IIS 10. Net framework is 4.5.2 and EF is 6. Matlab 2015Ra, VS2013, and IIS are 64 bit on windows 10 which is also 64 bit. I have MatLab script compiled as net assembly. When I use development server, the program works fine without error, while when it is deployed on IIS program fails to execute MatLab code with this exception message:</p>
  
  <p>The MATLAB runtime instance could not be initialized
  segv - SEVERE ERROR</p>
  
  <p>Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. </p>
  
  <p>Exception Details: System.ApplicationException: The MATLAB runtime instance could not be initialized
  segv - SEVERE ERROR</p>
  
  <p>The complete stack trace is:</p>
  
  <pre><code>    [ApplicationException: The MATLAB runtime instance could not be initialized
      segv - SEVERE ERROR] MathWorks.MATLAB.NET.Utility.MWMCR..ctor(String componentId, String componentPath, Stream embeddedCtfStream, Boolean isLibrary) +282
  
      [Exception: The MATLAB runtime instance could not be initialized]
      MathWorks.MATLAB.NET.Utility.MWMCR..ctor(String componentId, String componentPath, Stream embeddedCtfStream, Boolean isLibrary) +736
      BuildCrop.Cropper..cctor() +390
  
      [Exception: MWArray assembly failed to be initialized]
      BuildCrop.Cropper..ctor() +43
      EMS.Controllers.AdministratorController.Test_CreateCrop() +186
      lambda_method(Closure , ControllerBase , Object[] ) +87
      System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext 
      controllerContext, IDictionary`2 parameters) +229
  
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +35
    System.Web.Mvc.Async.AsyncControllerActionInvoker.&lt;BeginInvokeSynchronousActionMethod&gt;b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +39
    System.Web.Mvc.Async.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult) +67  
    System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod (IAsyncResult asyncResult)+42
    System.Web.Mvc.Async.AsyncInvocationWithFilters.&lt;InvokeActionMethodFilterAsynchronouslyRecursive&gt;b__3d() +72
    System.Web.Mvc.Async.&lt;&gt;c__DisplayClass46.&lt;InvokeActionMethodFilterAsynchronouslyRecursive&gt;b__3f() +386   
    System.Web.Mvc.Async.AsyncControllerActionInvoker. EndInvokeActionMethodWithFilters  (IAsyncResult  asyncResult) +42
    System.Web.Mvc.Async.&lt;&gt;c__DisplayClass2b.&lt;BeginInvokeAction&gt;b__1c() +38
    System.Web.Mvc.Async.&lt;&gt;c__DisplayClass21.
    &lt;BeginInvokeAction&gt;b__1e(IAsyncResult asyncResult) +186
    System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction (IAsyncResult asyncResult) +38
    System.Web.Mvc.Controller.&lt;BeginExecuteCore&gt;b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +29
    System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +65
    System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53
    System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +36
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +38
   System.Web.Mvc.MvcHandler.&lt;BeginProcessRequest&gt;b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +44
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +65
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +38   
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication. IExecutionStep.Execute() +399
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) +157
  </code></pre>
  
  <p>I have looked at various solutions and articles, also tried solutions suggested by Leon on <a href="https://www.mathworks.com/matlabcentral/answers/29604-issues-with-iis-6-and-matlab-runtime" rel="nofollow noreferrer">https://www.mathworks.com/matlabcentral/answers/29604-issues-with-iis-6-and-matlab-runtime</a> and  L. Mar in <a href="http://do-the-right-things.blogspot.com.au/2011/06/caveat-in-using-matlab-dll-in-aspnet.html" rel="nofollow noreferrer">http://do-the-right-things.blogspot.com.au/2011/06/caveat-in-using-matlab-dll-in-aspnet.html</a></p>
  
  <p>I also increased the server.scripttimeout in IIS but the same error message appears. </p>
  
  <p>PS: Matlab is installed on server and dlls are created from same Matlab. </p>