MWMCR exception - Attempted to read or write protected memory.

I have made a Matlab .dll with my .NET builder, but when i try to access the class MDClass in my namespace MelanomaDetection get the following error:
{"The type initializer for 'MelanomaDetection.MDClass' threw an exception."}
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
MWArray at MathWorks.MATLAB.NET.Utility.MWMCR.mclIsMCRInitialized() at MathWorks.MATLAB.NET.Utility.MWMCR..cctor()
I just initialize it like this:
var m = new MDClass();
I don't have any restrictions in my Matlab program, neither in my .NET app.
Thanks in advance for any help!

回答 (2 件)

Kaustubha Govind
Kaustubha Govind 2011 年 10 月 7 日

1 投票

Have you copied mclmcrrt7x.dll to a location outside of the MCR installation directory? It looks like that could cause this error: http://www.mathworks.com/support/solutions/en/data/1-AN5VOX/index.html

8 件のコメント

Kim
Kim 2011 年 10 月 7 日
I have included it in my project.
Before the above error, i got the error that it was missing, so i added it, and it disappeared :)
Kaustubha Govind
Kaustubha Govind 2011 年 10 月 10 日
The right think to do is to add the path to the mclmcrrt7x.dll to the system PATH variable. You need to install the MCR and then add mcr_root\ver\runtime\win32|win64 to the top of the system path. See http://www.mathworks.com/help/toolbox/compiler/f12-999353.html#br2jauc-34
Kim
Kim 2011 年 10 月 11 日
It looks like it is already added: "C:\Program Files (x86)\MATLAB\MATLAB Compiler Runtime\v715\runtime\win32".
I'm running on a 64-bit w7, and im executing my code on a 64-bit Windows Server 2008 R2.
Could this have any effect?
Kaustubha Govind
Kaustubha Govind 2011 年 10 月 12 日
Yes! You need to have the 64-bit MCR installed and added to path.
Kim
Kim 2011 年 10 月 27 日
Even when my Matlab runs 32-bit?
Kaustubha Govind
Kaustubha Govind 2011 年 10 月 28 日
No, if you're compiling with 32-bit MATLAB, you need 32-bit MCR.
Kim
Kim 2011 年 10 月 31 日
Okay, then could it be my runtime environment that is wrong? is there any special features you have to set up?
I'm running the newest MCR 7.16, and my .dll has been compiled in Matlab 2011b, so that should fit.
The MCR still crashes though...
Kaustubha Govind
Kaustubha Govind 2011 年 10 月 31 日
Kim: Perhaps it will be best if you contact MathWorks Tech Support about this, since you seemed to have tried a lot of things already?

サインインしてコメントする。

Guy
Guy 2011 年 10 月 20 日

0 投票

I've discovered a problem with mclIsMCRInitialized(), and raised it here some four months ago, in that if you try to call this function and the MCR is not initialized, then it doesn't return 0 as documented, but rather crashes with a segmentation fault. This doesn't make it terrible useful. I'd be interested to know if you're testing the return value of this function in order to then decide whether to call mclInitializeApplication(). If so, then it sounds like the same issue and I can only suggest forcing an initial MCR initialization, rather than making it conditional on a returned value of 0 from mclIsMCRInitialized().

1 件のコメント

Kim
Kim 2011 年 10 月 25 日
I can't seem to force an MCR initialization, how would you do this?
I've tried with InitializeApplication() but it doesn't seem to work.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeC Shared Library Integration についてさらに検索

質問済み:

Kim
2011 年 10 月 7 日

Community Treasure Hunt

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

Start Hunting!

Translated by