R in WCF and return large set of Data

Jan 14, 2016 at 6:07 PM
I have an issue with my R.NET use in WCF services.

  1. Application client send data to WCF service
  2. WCF :
    a-convert data to DataFrame
    b-call R script (result as DataFrame)
    c-convert Dataframe to Object and return it
  3. Client get the result
It works great with small quantity of data (100 rows, 50 columns).

But with a large collection (Dataframe with 5000 rows, 50 columns) the application Pool of WCF (hosted in IIS) crash at the end of the execution (during returning data (after step 2.c)

Anyone have an idea of my problem?
There is any know issue using WCF with r.net ?

Thanks in advance,

In the event viewer:
Faulting application name: w3wp.exe, version: 7.5.7601.17514, time stamp: 0x4ce7afa2
Faulting module name: R.dll, version: 3.22.3517.0, time stamp: 0x55cdbbac
Exception code: 0xc00000fd
Fault offset: 0x0000000000023091
Faulting process id: 0x17c8
Faulting application start time: 0x01d14e2c7db0a182
Faulting application path: c:\windows\system32\inetsrv\w3wp.exe
Faulting module path: C:\R\bin\x64\R.dll
Report Id: f8982ba6-ba1f-11e5-a251-00155d8378f6

Example of my WCF service
 public class ComputeService : IOptimizationService
        private REngine _engine;

        public ComputeService()

        public OutputData Launch(InputData input)
               Log.Init("ApplicationLogger", LogLevel.Debug);
               Log.Debug("Launch Compute service");

               Log.Debug("Init R");
               // Init R.net library
               _engine = REngine.GetInstance();

               Log.Debug("Load R script");

               // Script R path

               //Preparing data to be passed to R .Net
               Log.Debug("Create demands dataframe");
               DataFrame myDataFrame = input.ToDataFrame(_engine);

               //R execution
               var optimizationRFunction = _engine.Evaluate("myFunction").AsFunction();

               Log.Debug("Launch R script");
               DataFrame optimizationResult = optimizationRFunction.Invoke(myDataFrame).AsDataFrame();
               Log.Debug("End R script");

               // //Result
               Log.Debug("Output : Begin");
               DataTable output = ConvertToDataTable(optimizationResult,"OptimizationResults");
               Log.Debug("End Compute service");
                // return data
                return output;
            catch (Exception ex)
                // check numero error
                // Manage type of faultException
                throw new FaultException(ex.Message);
Jan 22, 2016 at 10:59 AM
There is no obvious cause that I can see. A couple of suggestions you may consider to further diagnose the problem:
  • Is running functionally the same code in a single process (no WCF, no IIS) reproducing the issue.
  • Compile in debug mode and attach the running process executing ComputeService to Visual Studio, to get more information in inspect the call stack to get more information.
Jan 22, 2016 at 11:24 AM
Thank you for your feedback.

Yesterday, we have tested in Console App, and it working normaly.

So we test to use our WCF self hosted (in console App).
And the result was good. No crash, console app continue to work. No problem after several calls of the service.

I think IIS perform some actions on the memory.
Finally we keep Self hosted solution (We can also try to use Windows Services host)