title: Load dll's from Environment Variable Path from a service
body: <p>We install Matlab Runtime on a machine, then we restart a .net windows service that invokes methods from the Matlab Runtime.<br>
  The problem is that we receive TypeInitializationException errors until we restart windows.
  We think this happens because <a href="http://support.microsoft.com/kb/821761" rel="nofollow noreferrer">Environment Variables are not changed on services until restart</a> and Matlab uses the %Path% variable to reference it's core DLL's.<br>
  My question is, do you think I can change the %Path% variable so that Matlab will use it when referencing the core dll's for it's engine?<br>
  Or is it possible to add a directory to the runtime DLL loading mechanism of .NET so that those Matlab core dll's would be referenced correctly without restarting the machine?</p>
  
  <p>Here is the exception we get</p>
  
  <pre><code>System.TypeInitializationException: The type initializer for 'MatlabCalculation.Calculation' threw an exception. ---&gt; System.TypeInitializationException: The type initializer for 'MathWorks.MATLAB.NET.Utility.MWMCR' threw an exception. ---&gt; 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()
  </code></pre>
  
  <p>"Kan opgegeven module niet vinden" = "The specified module not found"</p>