Originally posted by: rapherd
Hello Guys,
I'm developing an application which is based on C# programming language. This application needs OPL support to solve some mathematical optimization tasks.
For that reason I decided to develop a web service that encapsulates the OPL staff (model creation, solving model, extracting results, etc.). the web service is a simple .NET bases WCF service.
I did it and it at first it seems to be great until I called the service several times. After a few calls (lets assume 3-5 calls) the IIS application pool where the service is hosted in, is crashed and the windows Eventlog shows, that the CPLEX .NET wrapper is responsible for the crash.
The Eventlog shows:
############################################################
An unhandled exception occurred and the process was terminated.
Application ID: /LM/W3SVC/1/ROOT/MasterPlanningService
Process ID: 15784
Exception: System.ArgumentException
Message: Cannot pass a GCHandle across AppDomains.
Parameter name: handle
StackTrace: at System.Runtime.InteropServices.GCHandle.InternalCheckDomain(IntPtr handle)
at System.Runtime.InteropServices.GCHandle..ctor(IntPtr handle)
at System.Runtime.InteropServices.GCHandle.FromIntPtr(IntPtr value)
at ILOG.Concert.Cppimpl.concert_wrap.doCallNotifierStream_free(Int32 objectPtr)
at ILOG.Concert.Cppimpl.concert_wrapPINVOKE.delete_NotifierStream(IntPtr jarg1)
at ILOG.Concert.Cppimpl.NotifierStream.Dispose()
at ILOG.Concert.Cppimpl.NotifierStream.Finalize()
############################################################
Based on that error, the .NET runtime instance itself crashes of course.
My first intension was that I forgot to close an OPL handle, so that the CPLEX environment is not destroyed correctly. Therefore, I copied the code from the "cutstock" C# example that is shipped with the opl installation into my web service and the error still occurs.
Can anyone help me with this specific error? I know it's a very specific problem but maybe you also have an idea how I can realize my requirements in a different way?
One solution is to write a C# or even C++ console application and call this application within the web service. But that's a very poor and inefficient design and my very last solution.
One last thing: It's not possible to directly use the CPLEX C# API within my application. The reason for that is that my application is old and needs .NET 2.0 runtime while CPLEX uses a new .NET 4.0 runtime.
Thank you very much for each hint or idea.
Regards
Raphael
#DecisionOptimization#OPLusingCPLEXOptimizer