Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

engine.Evaluate("library(xgboost)") throws StackOverflow error. #74

Open
abidzar opened this issue Apr 12, 2018 · 12 comments
Open

engine.Evaluate("library(xgboost)") throws StackOverflow error. #74

abidzar opened this issue Apr 12, 2018 · 12 comments
Labels
bug IIS R.NET from IIS via ASP.NET

Comments

@abidzar
Copy link

abidzar commented Apr 12, 2018

My environment:

Windows 7 - 64
Visual Studio 2015
Version: R 3.4.4
R platform: i386-w64-mingw32

Not able to load library although the library xgboost is installed and located in R_HOME library folder.

Other library catools can be loaded fine. However, xgboost throws Stackoverflow error.

@lrasmus
Copy link
Contributor

lrasmus commented Apr 13, 2018

Curious if you have tested it with other versions of R, or just 3.4.4?

@lrasmus
Copy link
Contributor

lrasmus commented Apr 13, 2018

I tested this on:

Windows 10 - 64
Visual Studio 2015
Version: R 3.4.0 and 3.4.4

For each version of R, I used this code and did not get an exception. Just curious how to replicate the same issue you're seeing. I will note that I pulled down R.NET from NuGet and used that. Are you using a locally built version?

https://gist.github.com/lrasmus/1decc4c4af6dc61e45167a64b638c2f0

using RDotNet;

namespace RDotNetTester
{
    class Program
    {
        static void Main(string[] args)
        {
            REngine.SetEnvironmentVariables();
            var engine = REngine.GetInstance(null, true, null);
            engine.Evaluate("library(xgboost)");
        }
    }
}

@abidzar
Copy link
Author

abidzar commented Apr 13, 2018

I only tested againts R3.4.4

I'm using .R NET package from nuget as well.
My packages are:

<packages>
  <package id="Antlr" version="3.4.1.9004" targetFramework="net461" />
  <package id="bootstrap" version="3.0.0" targetFramework="net461" />
  <package id="DynamicInterop" version="0.8.1" targetFramework="net461" />
  <package id="jQuery" version="1.10.2" targetFramework="net461" />
  <package id="jQuery.Validation" version="1.11.1" targetFramework="net461" />
  <package id="Microsoft.AspNet.Mvc" version="5.2.3" targetFramework="net461" />
  <package id="Microsoft.AspNet.Razor" version="3.2.3" targetFramework="net461" />
  <package id="Microsoft.AspNet.Web.Optimization" version="1.1.3" targetFramework="net461" />
  <package id="Microsoft.AspNet.WebPages" version="3.2.3" targetFramework="net461" />
  <package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.0" targetFramework="net461" />
  <package id="Microsoft.jQuery.Unobtrusive.Validation" version="3.2.3" targetFramework="net461" />
  <package id="Microsoft.Net.Compilers" version="1.0.0" targetFramework="net461" developmentDependency="true" />
  <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net461" />
  <package id="Modernizr" version="2.6.2" targetFramework="net461" />
  <package id="Newtonsoft.Json" version="6.0.4" targetFramework="net461" />
  <package id="R.NET" version="1.7.0" targetFramework="net461" />
  <package id="Respond" version="1.2.0" targetFramework="net461" />
  <package id="WebGrease" version="1.5.2" targetFramework="net461" />
</packages>

The details error is:

An unhandled exception of type 'System.StackOverflowException' occurred in RDotNet.dll
In
{System.Collections.ListDictionaryInternal}

@lrasmus
Copy link
Contributor

lrasmus commented Apr 13, 2018

Thanks for the details - I updated my project to match, so it's now building against .NET 4.6.1 and I've installed all of the same packages (although they are not needed in my instance, but just to get on the same ground).

Unfortunately I don't get the exception. I was wondering if you could create a simple command line project based on the code I had posted before and see if you can replicate the problem? You're not the only one seeing this - there's a SO post with the same general approach and error.

@abidzar
Copy link
Author

abidzar commented Apr 13, 2018

Thank you for your suggestion,
I tried creating simple console application and it works fine.

However, using MVC web application on the same settings it throws the error.

What could be the solution?
Thanks,
-Abi

@lrasmus
Copy link
Contributor

lrasmus commented Apr 13, 2018

Ahhh! Okay, that's good to know. I'll try and replicate this with a simple MVC web application to see if I can get the exception now.

@lrasmus
Copy link
Contributor

lrasmus commented Apr 27, 2018

So, I think I've somewhat replicated your problem - but what's odd is I get a different exception. I created a simple MVC controller and call the following code:

REngine.SetEnvironmentVariables();
var engine = REngine.GetInstance();
engine.Evaluate("library(caTools)");
engine.Evaluate("library(xgboost)");

It loads caTools fine, and throws an RDotNet.EvaluationException when trying to load xgboost (not StackOverflow):

RDotNet.EvaluationException was unhandled by user code
  HResult=-2146233088
  Message=Error: package or namespace load failed for 'xgboost' in inDL(x, as.logical(local), as.logical(now), ...):
 unable to load shared object 'C:/Program Files/R/R-3.4.4/library/stats/libs/i386/stats.dll':
  LoadLibrary failure:  The specified module could not be found.

  Source=RDotNet
  StackTrace:
       at RDotNet.REngine.Parse(String statement, StringBuilder incompleteStatement)
       at RDotNet.REngine.<Defer>d__46.MoveNext()
       at System.Linq.Enumerable.LastOrDefault[TSource](IEnumerable`1 source)
       at RDotNet.REngine.Evaluate(String statement)
       at RDotNetTest.Controllers.DefaultController.Index() in C:\Development\RDotNetTest\RDotNetTest\Controllers\DefaultController.cs:line 18
       at lambda_method(Closure , ControllerBase , Object[] )
       at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)

I was wondering where and how you're initializing the REngine in your application, and how you're calling code to execute? Are you doing it all from within a single controller action?

@mentezam-nf
Copy link

I'm having the same problem. It happens for some libraries (e.g. plyr, dplyr, tidyr, xml2) and not others (e.g. sqldf, jsonlite). The thing is that this only happens when I'm testing/running in IIS Express and not in Console app or MS Test classes. Here are my specs:
R 3.4.3
R.NET 1.7.0
VS 2017 (.NET Framework 4.5.2)

I've tried using 32-bit and 64-bit R and same results.

@abidzar
Copy link
Author

abidzar commented May 12, 2018 via email

@jmp75
Copy link
Collaborator

jmp75 commented May 12, 2018

@mentezam-nf @abidzar @lrasmus I have not looked in details, nor reproduced, and I do little to no web dev, but my understanding is that IIS expect thread safe code, and the R engine is NOT thread safe. I may be off the mark here but my experience is that IIS and R via R.NET do not play well.

@jmp75 jmp75 added IIS R.NET from IIS via ASP.NET bug labels May 12, 2018
@mentezam-nf
Copy link

Yes, I'm aware of the threading issue but I don't think that this is the problem here. I've already put in code to synchronize thread access to the REngine instance. The problem happens when calling library() on the packages that I mentioned. It throws a StackOverflowException.

@mentezam-nf
Copy link

I figured out the issue. I posted my solution on SO:

https://stackoverflow.com/questions/49623768/an-unhandled-exception-of-type-system-stackoverflowexception-occurred-in-rdotn/50381186#50381186

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug IIS R.NET from IIS via ASP.NET
Projects
None yet
Development

No branches or pull requests

4 participants