When attempting to build a project that references MATLAB's MWArray.dll, NCrunch generates the following error message:
CSC (0)#1: Metadata file 'c:\Users\cshoutc\AppData\Local\NCrunch\8484\109\_ncrunchreferences\MWArray.dll' could not be opened -- 'Error importing module 'ManagedCPPAPI.netmodule' of assembly 'c:\Users\cshoutc\AppData\Local\NCrunch\8484\109\_ncrunchreferences\MWArray.dll' -- The system cannot find the file specified. '
This project builds fine using Visual Studio locally or MSBuild on the CI server. Any suggestions? I have verified that the MATLAB Compiler Runtime v7.13 is installed and have rebooted since installation. I'm fresh out of ideas.
I haven't heard of anyone using NCrunch with a MATLAB project before, so this is uncharted territory .. but let's see if we can get this to work :)
If you right click on the project with a failing build, then choose Advanced->Browse to workspace, can you find the MWArray.dll file in the workspace at the expected path?
Adjusting the 'Include static references in workspace' option MAY solve this problem - although I'm hoping to remove this configuration option soon, so it would be good to figure out why this isn't working. Is there also any chance you could submit a bug report after the build fails?
Remco wrote:
If you right click on the project with a failing build, then choose Advanced->Browse to workspace, can you find the MWArray.dll file in the workspace at the expected path?
I have checked the workspace and verified that MWArray.dll does exist at the expected path
Remco wrote:
Adjusting the 'Include static references in workspace' option MAY solve this problem - although I'm hoping to remove this configuration option soon, so it would be good to figure out why this isn't working.
The 'Include static references in workspace' option was set to 'True' for all of my projects. Setting that option to 'False' for the projects with a reference to MWArray.dll appears to have fixed the build issue. When NCrunch attempts to run the related unit tests however, they fail with the following error message:
System.BadImageFormatException: Could not load file or assembly 'MWArray, Version=2.10.0.0, Culture=neutral, PublicKeyToken=e1d84a0da19db86f' or one of its dependencies. An attempt was made to load a program with an incorrect format.
File name: 'MWArray, Version=2.10.0.0, Culture=neutral, PublicKeyToken=e1d84a0da19db86f' ---> System.BadImageFormatException: Could not load file or assembly 'file:///C:\AnonymousSolution\lib\Matlab\MWArray.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format.
File name: 'file:///C:\AnonymousSolution\lib\Matlab\MWArray.dll'
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark)
at System.Reflection.Assembly.LoadFrom(String assemblyFile)
at nCrunch.Common.CustomAssemblyResolver.ResolveAssemblyWithShortName(String shortAssemblyName)
at nCrunch.Common.CustomAssemblyResolver.#=qv0KZ_UwTbsHg6IgpYUSrs9wZQLwP1D4aQqcSl6MVHPU=(Object #=qsmZFRLWL1wlpfQ6z355tLw==, ResolveEventArgs #=qIjyzl5SKDG0dmtpmuiVHQA==)
at System.AppDomain.OnAssemblyResolveEvent(RuntimeAssembly assembly, String assemblyFullName)
at AnonymousSolution.Tests.Matlab.MatlabConverterTest.ToMwCellArrayTest()
The unit tests all pass if I run them outside of NCrunch with MSTest or ReSharper.
Remco wrote:
Is there also any chance you could submit a bug report after the build fails?
I submitted a bug report after a failed rebuild attempt as requested.
Thank you very much for your assistance thus far and please let me know if you need any more information to determine the root cause.
I've looked at this a bit deeper, and it looks like at this stage it won't be feasible to add support for MATLAB libraries with NCrunch. Sorry, there's not much I can do to help here.
I've looked at this a bit deeper, and it looks like at this stage it won't be feasible to add support for MATLAB libraries with NCrunch. Sorry, there's not much I can do to help here.
Cheers,
Remco
That's unfortunate, but thank you for looking into it. Do you have any more details about why it is infeasible? Is MATLAB doing some strange voodoo magic? I am quite curious about this!
It seems like the format of the MATLAB library is somehow inconsistent with a normal CLR reference. My theory is that there must be some kind of injection point or custom build step that is specific to MATLAB, but in all truth the problem leaves me quite clueless. The main barrier I found was in needing to set up and learn the dimensions of a new development environment in order to recreate and isolate the issue. At this stage in NCrunch's development it's difficult to commit the resources to this, though perhaps it could be looked into at a later date.