Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Asp.Net应用程序中的Mathematica.Net/Link_C#_Asp.net_.net_Wolfram Mathematica - Fatal编程技术网

C# Asp.Net应用程序中的Mathematica.Net/Link

C# Asp.Net应用程序中的Mathematica.Net/Link,c#,asp.net,.net,wolfram-mathematica,C#,Asp.net,.net,Wolfram Mathematica,我正在使用Mathematica创建一个web服务来格式化和计算数学问题。然而,我无法让它工作 我使用以下代码创建它: _Log.IpDebug("Starting the Kernel Link"); if (string.IsNullOrEmpty(_MathLinkArguments)) _InternelKernel = MathLinkFactory.CreateKernelLink(); else _InternelKernel = MathLinkFactory.Cre

我正在使用Mathematica创建一个web服务来格式化和计算数学问题。然而,我无法让它工作

我使用以下代码创建它:

_Log.IpDebug("Starting the Kernel Link");
if (string.IsNullOrEmpty(_MathLinkArguments))
   _InternelKernel = MathLinkFactory.CreateKernelLink();
else
   _InternelKernel = MathLinkFactory.CreateKernelLink(_MathLinkArguments);
_Log.IpDebug("Kernel Link Started");
_InternelKernel.WaitAndDiscardAnswer();
\u MathLinkArguments
的值是
-linkmode launch-linkname\“C:\\Program Files\\Wolfram Research\\Mathematica\\7.0\\Math.exe\”

这段代码是从global.asax.cs文件的
应用程序\u Start
方法调用的

当它到达
WaitAndDiscardAnswer()
调用时,它给出服务器错误:

Error code: 11. Connected MathLink program has closed the link, but there might still be data underway. 
注意:与.NET/Link包(控制台应用程序和WinForms应用程序)一起提供的示例代码有效

编辑: 我将Mathematica提供的控制台应用程序示例代码复制到asp.net页面中,在第一次加载时,它给了我相同的错误,然后在后续加载时,它给了我相同的错误:

Error code: 1. MathLink connection was lost.
编辑2:
我忘了提到,当我在运行我的应用程序时打开procmon和任务管理器时,我可以判断Math.exe启动但它立即退出,这使得这些错误代码完全有道理……但没有解释为什么会发生这种情况。

允许.Net/链接在Asp.Net中工作(至少在IIS 7.5中)您需要在网站的应用程序池上启用属性
loadUserProfile

我不完全确定为什么会出现这种情况,但从我在调试时发现的情况来看,有些东西是从用户的配置文件中获得的。我知道内核的默认位置是,这解释了为什么我不能在没有参数的情况下使用它,因此我只能假设还需要其他东西,如果没有配置文件,它无法确定这一点


但无论是什么原因,这都是必需的,或者如果您在自己的应用程序中遇到类似的问题,至少这是一个解决方案。

我在.Net WinForm应用程序中遇到了相同的错误

mathKernel = new MathKernel();
mathKernel.Compute("<< XYZ`XYZGraphs`");  
编辑:

我再次收到错误,这次能够确定问题所在

使用命令行打开MathKernel.exe并查看错误消息:


您的问题不清楚它是否在未指定参数的情况下工作。您是否检查了_InternelKernel变量是否不为null?我相信您知道linkname只是一个字符串,不必这么复杂。唯一标识符是可以的。在Mathematica
kernel=LinkLaunch[“C:\\Program Files\\Wolfram\Research\\Mathematica\\7.0\\MathKernel.exe”“-linkmode launch-linkname uniqueIdentifier123]”中是否可以执行以下操作:;打印[LinkRead[kernel]];LinkClose[kernel]
它也不能在没有参数的情况下工作,但错误是它只是挂起,从不加载页面。另外,当我在Mathematica中运行这段代码时,我得到了
InputNamePacket[in[1]:=]
您是否尝试创建一个独立的CS程序,其中包含与发布的代码等效的代码?它有效吗?我没有创建一个,但是它附带了2位示例代码,其中一个接受args的参数,我使用这里指定的参数来创建它,它有效。然后我尝试创建一个新页面,从控制台应用程序代码中复制/粘贴代码,这给了我相同的错误(第一次),然后
错误代码:1。MathLink连接丢失。
每当我刷新时。
if (!MathKernel.IsConnected)
{
    MathKernel.Connect();
}

if (MathKernel.IsComputing)
{
    MathKernel.Abort();
}