1

I have strange issue when I call matlab function from C# class. The most of time is everything ok but sometimes (1 call from 100 calls, maybe 1000 or one call in day for example - I can measure it in future) i get a strange MWMCR error. Of course the error cause the exception in my C# code. The behavior is same on two computers.

The message from the exception always seems as follows ... MWMCR::EvaluateFunction error ... The file "C:\Users\user\AppData\Local\Temp\VF\mcrCache9.2\Matlab1\Program Files\MATLAB\R2012b\work\frm\file_with_called_function.m" cannot be executed..

The details from the exception is Failed to open file 'C:\Users\user\AppData\Local\Temp\VF\mcrCache9.2\Matlab1\Program Files\MATLAB\R2012b\work\frm\file_with_called_function.m'. Details: 'File stream is closed. The following flags are set: failbit.'

And mscorelib error mscorlib::Void HandleReturnMessage(System.Runtime.Remoting.Messaging.IMessage, System.Runtime.Remoting.Messaging.IMessage)

(Of course I have the whole call stack but it does not seem very useful.)

As you can see I use MWMCR v 9.2. (MATLAB 9.2, release R2017a) and MWMCR works in user's temp directory. Interesting is when I explore the directory after error the directory is empty. I do not know that is normal behavior.

And the question. Why MWMCR sometimes can not open the file (evaluate the function)?? The related question is why is (in my case) failbit on the stream setted and why is filestream closed??

And subquestions. How MWMCR works with user's tmp folder? MWMCR copy the matlab file to the temp directory, works with them and delete them?? Why is directory empty??

Thank You.

4
  • This is most likely due to antivirus. If you have one, configure scanning to ignore mcr cache folder. Commented Jul 13, 2018 at 15:24
  • I thought it would be "antivirus problem" but on second machine (not my personal computer with Eset) is not a antivirus. At least not any special antivirus (only default apps from M$ like defender etc). Could it be the problem? Commented Jul 13, 2018 at 16:49
  • Couple of observations: a) why does the MCR directory contain files from R2012b, b) what does the surrounding code in c# do ? c) what data are you fetching from the matlab call ? on a side note, I would highly recommend you to reach out to the official technical support at Mathworks about this issue. Commented Jul 13, 2018 at 16:58
  • @PrateekKhandelwal a)I think it is not important but it is something about compiler version - maybe we use the wrong version of them b)C# code only prepare the data, call the matlab function with calculation (from small formula like factorial, for example, to complex calculations like decay of nuclide) and parse the results c)in this case the exception was threw, but generaly the results of calculations from b) - from one number to complex data structures of structures of arrays. (I will be contact official MW support later if I do not resolve the problem.) Commented Jul 13, 2018 at 18:34

1 Answer 1

2

The solution is change default cache location using env variable MCR_CACHE_ROOT to location under your control (like project directory, user directory, etc).

Explanation.

The runtime is not probably designed to run long time. It uses standard temporary location (tmp directory) for store scripts and can't find it when OS delete it after some time. Additionally runtime uses something like LRU cache what means that some files looking for in memory cache and some in filesystem cache.

When you always use files in memory cache everything is ok even is directory cache is empty. But when you fill memory cache and you want to use new function runtime tries load it from filesystem cache. When is filesystem cache has been deleted the error will occur.

In my case once per months (depends on type of calculations).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.