Message Boards Message Boards

Compiling C#, missing reference to ml64i4.dll, Mathematica 10

Posted 10 years ago

Good afternoon,

I'm struggeling for two days now, using google, Mathematica documentation center and other programming ressources to get my problem solved. I don't know how to get it solved. The final solution should be a working .NET dll, which I can use to call Mathematica from my SQL server (use it as a calculation engine). I have done this for version 9, but it's not working for version 10. Even the simple "Link Test" example is not working.

I have used this C# code from the documentation:

using System;
using Wolfram.NETLink;
public class LinkTest {
public static void Main(String[] args) {

    // This launches the Mathematica kernel:
    IKernelLink ml = MathLinkFactory.CreateKernelLink();

    // Discard the initial InputNamePacket the kernel will send when launched.
    ml.WaitAndDiscardAnswer();

    // Now compute 2+2 in several different ways.

    // The easiest way. Send the computation as a string and get the result in a single call:
    string result = ml.EvaluateToOutputForm("2+2", 0);
    Console.WriteLine("2 + 2 = " + result);

    // Use Evaluate() instead of EvaluateToXXX() if you want to read the result as a native type
    // instead of a string.
    ml.Evaluate("2+2");
    ml.WaitForAnswer();
    int intResult = ml.GetInteger();
    Console.WriteLine("2 + 2 = " + intResult);

    // You can also get down to the metal by using methods from IMathLink:
    ml.PutFunction("EvaluatePacket", 1);
    ml.PutFunction("Plus", 2);
    ml.Put(2);
    ml.Put(2);
    ml.EndPacket();
    ml.WaitForAnswer();
    intResult = ml.GetInteger();
    Console.WriteLine("2 + 2 = " + intResult);

    // Always Close when done:
    ml.Close();
}
}

I compiled it to an executable:

C:\Windows\Microsoft.NET\Framework64\v2.0.50727>csc.exe /t:exe /out:F:\Temp\LinkTest\LinkTest.exe /r:F:\Temp\LinkTest\Wolfram.NETLink.dll F:\Temp\LinkTest\LinkTest.cs

On my laptop, the exe works well (as long as ml64i4.dll is accessible in %PATH%). On the server, the exe only works if ml64i4.dll is in the same folder. I don't understand this. Some facts about my server machine:

  • Windows Server 2008 Enterprise x64, Build 6002, SP2
  • 4X4 CPU
  • 64 GB RAM
  • Mathematica 10.0.0 is installed and runs ok (front-end, kernel, etc.)
  • .NET Framekwork 2.0.50727 installed

I have copied ml64i4.dll to various system folders (C:\Windows, C:\Windows\system, ...), but it's not working. I need to get this fixed to compile my .NET dll for SQL.

The error message is:

Unhandled Exception:
System.TypeInitializationException:
The type initializer for 'Wolfram.NETLink.Internal.NativeLink' threw an exception. ---> System.DllNotFoundException:
Unable to load DLL 'ml64i4.dll':
The specified module could not be found. (Exception from HRESULT: 0x8007007E) at
Wolfram.NETLink.Internal.Win64MathLinkAPIProvider.MLBegin(IntPtr zero) at Wolfram.NETLink.Internal.NativeLink..cctor() --- End of inner
exception stack trace --- at Wolfram.NETLink.Internal.NativeLink..ctor(String cmdLine) at Wolfram.NETLink.MathLinkFactory.CreateKernelLink() at 
LinkTest.Main(String[] args)

The SQL server error message is similar:

Msg 6522, Level 16, State 1, Procedure CallMathematica, Line 0
A .NET Framework error occurred during execution of user-defined routine or aggregate "CallMathematica":
System.TypeInitializationException: The type initializer for 'Wolfram.NETLink.Internal.NativeLink' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'ml64i4.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
System.DllNotFoundException: 
at Wolfram.NETLink.Internal.Win64MathLinkAPIProvider.MLBegin(IntPtr zero)
at Wolfram.NETLink.Internal.NativeLink..cctor()
System.TypeInitializationException: 
at Wolfram.NETLink.Internal.NativeLink..ctor(String cmdLine)
at Wolfram.NETLink.MathLinkFactory.CreateKernelLink()
at MathLinkCLR.Call(SqlString MLInput, SqlString& MLOutResult, SqlString& MLOutMessage, SqlString& MLOutPrint)

I think it's related to the server operating system. Do you have any ideas how to fix it? Any help is greatly appreciated. As I am not an .NET expert, a "verbose" answer would be nice. Thanks!

I'm sorry, but I must have been very blind. The %PATH% was not including the WOLFRAM LIBRARY FOLDER. It was not added by default.

Group Abstract Group Abstract