Hi,
I am trying to make a Wolfram Mathematica call from an ArcGIS Pro add-in with C# like this:
using ArcGIS.Desktop.Framework.Contracts;
using System;
using System.Diagnostics;
using Wolfram.NETLink;
namespace MyAddIn
{
internal class MathematicaButton : Button
{
protected override void OnClick()
{
try
{
IKernelLink ml = MathLinkFactory.CreateKernelLink();
ml.WaitAndDiscardAnswer();
ml.Evaluate("2+2");
ml.WaitForAnswer();
int intResult = ml.GetInteger();
ml.Close();
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("2 + 2 = " + intResult);
}
catch (Exception ex)
{
Debug.WriteLine(ex.StackTrace);
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(ex.StackTrace);
}
}
}
}
I have included ml64i4.dll and Wolfram.NETLink.dll in my project.
When I run my add-in code I get this exception:
Exception thrown: 'System.TypeInitializationException' in Wolfram.NETLink.dll
at Wolfram.NETLink.Internal.NativeLink..ctor(String cmdLine)
at Wolfram.NETLink.MathLinkFactory.CreateKernelLink()
at MyAddIn.MathematicaButton.OnClick() in C:\Users\matti\Desktop\ArcGIS_Pro_add_in\MyAddIn\MathematicaButton.cs:line 14
Line 14 is:
IKernelLink ml = MathLinkFactory.CreateKernelLink();
If I run the same code in a console application it is working.
So my question is, what am I missing or doing wrong in the ArcGIS Pro add-in project?
Regards,
Mattias
Hi Mathias,
Have you tried right-clicking on the included ml64i4.dll file in Visual Studio and set Build Action to Content and Copy to Output Directory to Copy always (or Copy if newer)?
Best Regards,
/Markus
Yes. But it is still not working.