MATLAB: Does the MATLAB-compiled library (DLL) fail to initialize after creating a deployment package in Visual Studio

deploymentMATLAB Compilermclmcrrtpackagestudiovisual

I have created a DLL with the MATLAB compiler, and I am able to use it successfully in the context of a larger application I have created in Visual Studio. Since I want to deploy this application to another computer, I used Visual Studio to create a deployment package for installation on the deployment machine. After installing the deployment package, I observe the following error when executing my application:
System.ArgumentException: Generate Queries threw General Exception:
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at mclGetString_proxy(Void**, SByte*)
at mwArray.{ctor}(mwArray*, SByte* str)
at ISRWrapper.Wrapper.CsvsStats(String inFolder, String outFolder)
at ISRWrapper.Wrapper.CsvsStats(String inFolder, String outFolder)
at Presentation.Forms.QueryGenOptionsForm.btnGenQry_Click(Object sender, EventArgs e)

Best Answer

This change has been incorporated into the documentation in Release 2011a (R2011a). For previous releases, read below for any additional information:
This error is often caused by the presence of mclmcrrt7x.dll outside of the "mcr_root" directory, where "mcr_root" is the path to the installation directory of MATLAB Compiler. Sometimes this library gets placed in the installation directory of the deployment package, either by the developer or as the result of dependency calculations during the creation of the package. To work around this issue, inspect the installation directory and remove any instances of this or any other MCR libraries that you find.