MATLAB: Window Service crashes which is launching the Matlab processes out of process to perform some task

MATLABmatlab out of process taskwindows service crash

I am trying to run some task of Matlab as " out of process" task from My Windows Service. After comletion of that taks from Matlab process once the control comes back to my windows it shows crash by displaying the below error:–
Unhandled exception at 0x770207F2 (KernelBase.dll) in Sample.Test.Service.exe: 0xC0020001: The string binding is invalid (parameters: 0x8007042B).
The stack is :
> KernelBase.dll!_RaiseException@16() Unknown
clr.dll!COMPlusThrowBoot(long) Unknown
clr.dll!_UMThunkStubRareDisableWorker@8() Unknown
clr.dll!_UMThunkStubRareDisable() Unknown
mclmcr.dll!13b6880d() Unknown
[Frames below may be incorrect and/or missing, no symbols loaded for mclmcr.dll]
libmwservices.dll!0ebf4b6b() Unknown
libmwservices.dll!0ebf4d8a() Unknown
libmwservices.dll!0ebf4d2d() Unknown
[External Code]
libmwfl.dll!7e2637c5() Unknown
libmwfl.dll!7e2639b1() Unknown
[External Code]
libmwservices.dll!0ec104e0() Unknown
mlutil.dll!0fb08f15() Unknown
mlutil.dll!0fb09431() Unknown
[External Code]
libmwfl.dll!7e263677() Unknown
libmwfl.dll!7e263981() Unknown
[External Code]
mcr.dll!7cfdbd74() Unknown
mcr.dll!7cfdb12a() Unknown
mcr.dll!7cfdd024() Unknown
libut.dll!7f868009() Unknown
hg.dll!32326366() Unknown

Best Answer

This issue is happening due to MWObjectArray Limitation.
If you have any global objects in your C# code then you will get a Windows® exception on exiting the application. To overcome this limitation, use one of these solutions:
  • Explicitly clear global objects before exiting the application.globalObj.Destroy();
  • Call TerminateApplicationEx method before exiting the application.MWMCR.TerminateApplicationEx();
Details:--