Is it not possible to run a dockerized .NET program developed in Windows, using the Matlab Runtime in a linux container?

8 views (last 30 days)
I have a .NET Core console program referencing MWArray.dll to be able to use a function that we developed with the MATLAB Compiler SDK (resulting in another DLL). On a Windows host with the MATLAB Runtime installed (9.6) there are no issues whatsoever and the program executes and performs as expected.
We want to run this program on a Linux machine, so we dockerized the program, installed the Linux MATLAB Runtime on it and run it. I also made a program with just the MWArray.dll and a call to MWMCR.IsMCRInitialized() to narrow the problem. This is the exception that throws everytime:
% System.TypeInitializationException: 'The type initializer for 'MathWorks.MATLAB.NET.Utility.MWMCR' threw an exception.'
% Inner Exceptions:
% TypeInitializationException: The type initializer for 'MathWorks.MATLAB.NET.Arrays.MWArray' threw an exception.
% DllNotFoundException: Unable to load shared library 'mclmcrrt9_6.dll' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libmclmcrrt9_6.dll: cannot open shared object file: No such file or directory
It seems that the dotnet runtime can't access the MCR of the container even though is installed and the proper environment variables set. Is this because of the MWArray.dll of the Windows MATLAB Runtime inside our project maybe? I thought the Runtime was cross-platform. Is this not supported?
This is the Dockerfile (using a local MATLAB Runtime so it does not have to download it everytime):
FROM mcr.microsoft.com/dotnet/core/runtime:2.2-stretch-slim AS base
COPY ["MatlabDockerTest/MATLAB_Runtime_R2019a_Update_1_glnxa64.zip", "/mcr-install/"]
# Install MATLAB Runtime (MCR) silently
RUN apt-get -qq update && apt-get -qq install -y unzip && \
mkdir /opt/mcr && \
cd /mcr-install && \
unzip -q MATLAB_Runtime_R2019a_Update_1_glnxa64.zip && \
./install -mode silent -agreeToLicense yes -destinationFolder /opt/mcr && \
cd / && \
rm -rf mcr-install
# Configure environment variables for MCR
ENV LD_LIBRARY_PATH=/opt/mcr/v96/runtime/glnxa64:/opt/mcr/v96/bin/glnxa64:/opt/mcr/v96/sys/os/glnxa64:/opt/mcr/v96/extern/bin/glnxa64
WORKDIR /app
FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch AS build
WORKDIR /src
COPY ["MatlabDockerTest/MatlabDockerTest.csproj", "MatlabDockerTest/"]
RUN dotnet restore "MatlabDockerTest/MatlabDockerTest.csproj"
COPY . .
WORKDIR "/src/MatlabDockerTest"
RUN dotnet build "MatlabDockerTest.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "MatlabDockerTest.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "MatlabDockerTest.dll"]

Answers (1)

Walter Roberson
Walter Roberson on 20 May 2019
The runtime is not cross platform. MCR is operating system specific and can only be used to run code that you could run in MATLAB for that operating system.
  • activex can only be used on windows
  • .net can only be used on windows
  • memory() can only be used on windows
  • toolboxes that are only available for windows do not become available on other operating systems by compiling them into an executable
  • .dll and .mexw64 and .mexw32 and linking .lib can only be used on windows
  • .so and .dyld and .mexmaci and .mexa64 cannot be used on windows
  5 Comments
Jon Franco
Jon Franco on 6 Nov 2019
As Walter Roberson says there is no direct way, but I managed to develop a workaround for our use case (it surely isn't for many use cases but it works for us, and it isn't pretty).
With the Compiler SDK we exported the function to Python. I learned Python from scratch and dockerized a program that used the resulting MATLAB function, which generated CSV files with the results. Then, with a C# dockerized program (we HAD to use C# because our entire model is written in it) we grab those CSVs and parse them so we can, ultimately, work with the proper model objects.
I still think MATLAB .NET libraries should support running in Linux, but I guess it is something unusual.
I hope this helps.
jeremy engelbrecht
jeremy engelbrecht on 8 Nov 2019
Thank for the answer, I am also having to do a work aroung I have now created a linux Vm on aws installed docker, built my image on the linux VM. I have also added the Matlab runtime in the docker image but still having the same error. So I am looking at other workarounds.
But thanks for the feedback

Sign in to comment.

Categories

Find more on Get Started with MATLAB Compiler SDK in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!