我在这里使用的是R.NET dll: http://rdotnet.codeplex.com/ 我正在尝试从为Tradelink指定的自定义C#DLL中运行示例代码(http://code.google.com/p/tradelink) 这是代码。
using System;
using System.IO;
using System.Linq;
using RDotNet;
using TradeLink.Common;
using TradeLink.API;
using Microsoft.Win32;
namespace Responses
{
class RTLTest : ResponseTemplate
{
////static void Main(string[] args)
public override void GotTick(TradeLink.API.Tick k)
{
//Set the folder in which R.dll locates.
REngine.SetDllDirectory(@"C:\Program Files\R\R-2.12.0\bin\i386");
REngine.SetDllDirectory(GetRPath());
REngine.SetDllDirectory(@"C:\Program Files\R\R-2.14.1\bin\i386");
using (REngine engine = REngine.CreateInstance("RDotNet", new[] { "-q" })) // quiet mode
{
// .NET Framework array to R vector.
NumericVector group1 = engine.CreateNumericVector(new double[] { 30.02, 29.99, 30.11, 29.97, 30.01, 29.99 });
engine.SetSymbol("group1", group1);
// Direct parsing from R script.
NumericVector group2 = engine.EagerEvaluate("group2 <- c(29.89, 29.93, 29.72, 29.98, 30.02, 29.98)").AsNumeric();
// Test difference of mean and get the P-value.
GenericVector testResult = engine.EagerEvaluate("t.test(group1, group2)").AsList();
double p = testResult["p.value"].AsNumeric().First();
string s1 = String.Format("Group1: [{0}]", string.Join(", ", group1));
string s2 = String.Format("Group2: [{0}]", string.Join(", ", group2));
string s3 = String.Format("P-value = {0:0.000}", p);
senddebug(s1);
senddebug(s2);
senddebug(s3);
}
}
}
但我收到错误:
响应引发异常:无法加载文件或程序集“R.NET,Version = 1.4.0.0,Culture = neutral,PublicKeyToken = null”或其依赖项之一。试图加载格式不正确的程序。
任何人都可以帮忙解决这个问题吗?
答案 0 :(得分:0)
如果您的ASP.NET应用程序是64位,那么这可能是有用的http://blogs.msdn.com/b/rakkimk/archive/2007/11/03/iis7-running-32-bit-and-64-bit-asp-net-versions-at-the-same-time-on-different-worker-processes.aspx。 大多数R包dll(基本包除外)都是32位,因此它可能是问题的根源。