4

I have programmed this example for the last 6 years with various versions of Mathematica and .NET. This year I have moved to Version 10.0.2 and it doesn't work. I am using Visual Studio 12 for C#. My C# code is unremarkable:

string[] mlArgs = { "-linkmode", "launch", "-linkname", @"C:\Program Files\Wolfram Research\Mathematica\10.0\SystemFiles\Kernel\Binaries\Windows-x86-64\MathKernel.exe" };
            IKernelLink ml = null;
            try
            {
                ml = MathLinkFactory.CreateKernelLink(mlArgs);
                ml.WaitAndDiscardAnswer();
                string result = ml.EvaluateToOutputForm("2+2", 0);
                txtFirst.Text = result;
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
            finally
            {
                if (ml != null)
                    ml.Close();
            }

The ERROR I receive is:

"The type initializer for 'Wolfram.NETLink.Internal.NativeLink' threw an exception."

along with:

"Unable to load DLL 'ml32i4.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)"

Any help much appreciated!

Thank you,

Kieran

Karsten7
  • 27,448
  • 5
  • 73
  • 134
  • 1
    On my system the file ml32i4.dll is found in the following directory: \Mathematica\10.0\SystemFiles\Links\MathLink\DeveloperKit\Windows\SystemAdditions -- can you confirm that this file is present in your installation? – Mr.Wizard Feb 08 '15 at 10:41
  • It should also be somewhere in %PATH% if it's to be found after linking. Is it? (N.B. this is a solution to your problem as well as a question.) – Oleksandr R. Feb 08 '15 at 14:01

1 Answers1

6

In v10, the Windows version no longer installs the MathLink libraries to \Windows\System32. The recommended way of dealing with this is to 'redist' a copy of ml32i4.dll with the app.

ihojnicki
  • 3,026
  • 1
  • 16
  • 11
  • Where can one download the redistributable package? – Oleksandr R. Feb 09 '15 at 15:07
  • 1
    $InstallationDirectory\SystemFiles\Links[MathLink/WSTP]\DeveloperKit[Windows/Windows-x86-64]\SystemAdditions – ihojnicki Feb 09 '15 at 17:45
  • I see. Well, those are just the DLLs themselves; I was expecting that there would be a proper installer available for download that would use the "side-by-side assembly" mechanism. Otherwise, shared-memory links will not work, because this requires both ends of the link to have loaded the same library from the same location. This is the main reason one would use a DLL in the first place rather than statically linking. Or does MathLink 4 do something else as well to address that situation? – Oleksandr R. Feb 09 '15 at 22:58
  • Even i3 didn't have this requirement. – ihojnicki Feb 10 '15 at 02:19
  • And while it is kinda like using a static library, some languages cannot link against them. For instance, NETLink. As for the installer bit, requiring admin rights actually is a disadvantage at times. – ihojnicki Feb 10 '15 at 02:32
  • 1
    Thank you so much for your help. This has fixed the problem. I put the missing dll (copied from \Mathematica\10.0\SystemFiles\Links\MathLink\DeveloperKit\Windows\SystemAdditio​ns, note 64 bit versions also available) into the bin/debug or bin/release directory in my .NET project. Sorry for delay in responding - I was away. Best wishes, Kieran –  Feb 16 '15 at 08:25
  • @Kieran you should mark correct answers by ticking the holo checkbox next to answers. It will give you a couple of points and let everyone know your problem is solved! – WolframFan Jul 18 '15 at 04:57
  • This did not work at all for me. – Doug Kimzey Oct 27 '22 at 14:05