简体   繁体   English

在IIS中使用R.net运行外部库

[英]Running external libraries with R.net in IIS

We're trying to run R.net from an ASP.Net webpage in IIS, but encounter the problem that the R engine can't access external libraries. 我们正在尝试从IIS中的ASP.Net网页运行R.net,但是遇到R引擎无法访问外部库的问题。 I know this is a common problem, but the typical solutions haven't worked when it comes to IIS (only IIS express from inside VS). 我知道这是一个普遍的问题,但是当涉及到IIS时,典型的解决方案却没有用(仅VS内部的IIS Express)。

For example, when trying to use 'colorRampPalette' in R which relies on a DLL, the following error message appears: 例如,当尝试在依赖于DLL的R中使用'colorRampPalette'时,会出现以下错误消息:

"Error in inDL(x, as.logical(local), as.logical(now), ...) : unable to load shared object 'C:/Program Files/R/R-3.4.2/library/stats/libs/x64/stats.dll': LoadLibrary failure: The specified module could not be found." “ inDL(x,as.logical(local),as.logical(now),...)中的错误:无法加载共享对象'C:/ Program Files / R / R-3.4.2 / library / stats / libs / x64 / stats.dll':LoadLibrary失败:找不到指定的模块。”

It is not the stats.dll that is the problem, but rather another DLL it references. 问题不是stats.dll,而是它引用的另一个DLL。

Now, using the function in R works fine. 现在,在R中使用该功能可以正常工作。 Using the function from R.net in VS debugging works fine. 在VS调试中使用R.net中的功能可以正常工作。 However, running it from IIS does not work. 但是,无法从IIS运行它。 Normally, it's just a path variable missing to get it to work, but this doesn't seem to be the case here. 通常,只是缺少路径变量才能使其正常工作,但是这里似乎不是这种情况。

What we've tried: 我们尝试的是:

  • Ensured that the PATH variable has the necessary folders (ie C:\\Program Files\\R\\R-3.4.3\\bin\\x64 etc). 确保PATH变量具有必要的文件夹(即C:\\ Program Files \\ R \\ R-3.4.3 \\ bin \\ x64等)。 If this was wrong then R.net wouldn't work locally, and I've also verified that IIS doesn't reset the PATH variables which has been pointed out in other sources. 如果这是错误的,那么R.net将无法在本地工作,并且我还验证了IIS不会重置其他变量中已指出的PATH变量。 When I check the PATH variable from inside IIS the necessary folders are listed. 当我从IIS内部检查PATH变量时,列出了必要的文件夹。
  • Checked that the library, home and bin path in R.net is correct when running under IIS. 在IIS下运行时,检查R.net中的库,主目录和bin路径是否正确。
  • Ensured that the IIS_IUSRS user has read/write access to the necessary folders and files. 确保IIS_IUSRS用户对必需的文件夹和文件具有读/写访问权限。
  • Verified that the R code is correct. 验证R代码正确。

It seems that this is a common problem, but most solutions refer to making sure the PATH variable is correct, which simply isn't enough in this case. 看来这是一个普遍的问题,但是大多数解决方案都涉及确保PATH变量正确,在这种情况下,这仅仅是不够的。

We're running (Amazon web service): Windows Server 2016 x64, IIS 10, R.NET 1.7, C# 4.5.2, R 3.4.2 我们正在运行(Amazon Web服务):Windows Server 2016 x64,IIS 10,R.NET 1.7,C#4.5.2,R 3.4.2

I've also tried on another (non-AWS) server with a similar setup. 我还尝试了另一台具有类似设置的(非AWS)服务器。

Any ideas of what can cause this? 关于什么会导致这种情况的任何想法? Since a lot of people have issues with R.Net and IIS I suspect someone encountered the same problem where the PATH variable wasn't enough? 由于很多人都遇到R.Net和IIS问题,我怀疑有人遇到了相同的问题,而PATH变量还不够?

As mentioned by user2967150, It is not the stats.dll that is the problem, but rather another DLL it references. 如user2967150所述,问题不是由stats.dll引起,而是由它引用的另一个DLL。 After doing lot of research I found that It try to find Rlapack.dll in 'C:/Program Files/R/R-3.4.2/library/stats/libs/x64/ path. 经过大量研究后,我发现它尝试在'C:/ Program Files / R / R-3.4.2 / library / stats / libs / x64 /路径中找到Rlapack.dll。 so you just have to copy Rlapack.dll from 'C:\\Program Files\\R\\R-3.4.4\\bin\\x64 \\Rlapack.dll' to 'C:/Program Files/R/R-3.4.2/library/stats/libs/x64/ . 因此您只需要将Rlapack.dll从'C:\\ Program Files \\ R \\ R-3.4.4 \\ bin \\ x64 \\ Rlapack.dll'复制到'C:/ Program Files / R / R-3.4.2 / library / stats / libs / x64 /。 After this the web Application can access external R libraries. 之后,Web应用程序可以访问外部R库。

Note: I assume that your web Application Run locally but creates a problem when you try to run it on IIS. 注意:我假设您的Web应用程序在本地运行,但是当您尝试在IIS上运行它时会产生问题。

I was solving same issue. 我正在解决同样的问题。 For IIS I did not find the solution. 对于IIS,我没有找到解决方案。 I was also debugging the R.NET code, but solution by setting correct path to R folder did not work. 我也在调试R.NET代码,但是通过将正确的路径设置为R文件夹的解决方案不起作用。

The solution is created additional layer, which cover running R project (actually create own R server). 该解决方案创建了附加层,覆盖了正在运行的R项目(实际上是创建自己的R服务器)。 I used self hosted WCF service, 我使用了自托管WCF服务,

https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-host-a-wcf-service-in-a-managed-windows-service https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-host-a-wcf-service-in-a-managed-windows-service

which is practically console application and has benefits application running not in IIS application pool. 实际上是控制台应用程序,它使不在IIS应用程序池中运行的应用程序受益匪浅。 This solution also cover singleton REngine problem. 此解决方案还解决了单例REngine问题。 In case you run the instance or REngine in IIS, there is no posibility dispose it, only by stop application pool. 如果您在IIS中运行实例或REngine,则没有可能通过停止应用程序池来处置它。 For self-hosted service you can set trigger for restarting application in case memory leak. 对于自托管服务,您可以设置触发器以在内存泄漏的情况下重新启动应用程序。

During this implementation I discover problem run R.NET again R 3.4.3 in debug mode on console application I get error "The library "..." could not be load", so I used the R 3.4.2. 在此实施过程中,我发现问题再次在控制台应用程序上以调试模式运行R.NET R 3.4.3,出现错误“无法加载库“ ...””,因此我使用了R 3.4.2。 which work nice. 哪个工作不错。 86x installation is required - independent the your application run in 64x/ANYCPU environment. 需要86x安装-与在64x / ANYCPU环境中运行的应用程序无关。

Have you found any other solution for that? 您是否找到了其他解决方案?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM