Compiled .NET assembly - MWMCR EvaluateFunction Error

1 view (last 30 days)
I've compiled a couple of Matlab functions into .NET assemblies. The first of the two accepts the path of a wavefile as an argument, and returns a large array containing the coefficients of an expansion of that wavefile onto a frame, as well as the frame onto which the wavefile was expanded (as a matlab struct array). The second function performs the opposite task - it takes as input an array of expansion coefficients along with a frame, and returns a reconstructed wavefile.
These two functions have been compiled into .NET assemblies, and I've been testing them in a simple console application in VS. In Matlab, the two output values returned by the "expander" function may be provided directly to the "reconstructor" function and it will return the expected output. However, when I try to do this in VS, the call to the reconstruction function raises an MWMCR EvaluateFunction Error:
I really can't make any sense of the error message. The second argument to the reconstructor function is a struct array that does contain some function handles, but passing this struct array as an argument to the function body in matlab raises no errors - why should it raise one here?
The bodies of the two Matlab functions are:
function [coefficients, analysis_frame] = gammatone_expansion(wavefile)
% Expands a wavefile onto a frame of gammatone functions
wave = audioread(wavefile);
fc_data = load('fc_optim_43_2diff.mat');
fc = fc_data.optimresults2.x;
fs = 44100;
gambank = gammaSOS(fc, fs, 4, 'twodiff');
gambank_IR = cell(length(fc), 1);
for ii = 1:length(fc)
gambank_IR{ii, 1} = impz(gambank{ii}, 8192);
end
analysis_frame = frame('filterbank', gambank_IR, ones(43, 1), 43);
coefficients = frana(analysis_frame, wave);
and
function wave = gammatone_reconstruction(coefficients, analysis_frame)
% reconstructs a wavefile from a set of expansion coefficients after identifying an appropriate dual frame
synthesis_frame = frametight(analysis_frame);
wave = frsyn(synthesis_frame, coefficients);
the frame functions (frame, frana, frametight, frsyn) are from LTFAT

Answers (1)

Yeshwanth Devara
Yeshwanth Devara on 14 Nov 2016
Is it possible that the bitness of the applicaiton you compiled and the visual studio project are different? Note that in order to call a 64-bit .NET assembly DLL properly, the C# application in Visual Studio needs to be compiled in 64-bit as well. It is possible that in your Visual Studio project, you haven't changed the Solution Platform from "Any CPU" to "x64".
In Visual Studio, the "Any CPU" configuration defaults to 32-bit. The MATLAB function calls a MEX file behind the scene. MEX files are platform- and bitness- and specific. Builder NE packages the 64-bit MEX file during the compilation process and leaves out the 32-bit one. As a result, the 32-bit MCR launched by the EXE built in Visual Studio cannot find the right MEX file at runtime, which leads to the error.
Changing the solution platform to x64 in Configuration Manager should resolve this issue.
This article on StackOverflow contains detailed steps on how to change the solution platform to x64:
  1 Comment
Yeshwanth Devara
Yeshwanth Devara on 14 Nov 2016
You can change the project to 32 bit if your MATLAB applicaiton is 32 bit.

Sign in to comment.

Categories

Find more on C Shared Library Integration in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!