Message Boards Message Boards

Launch C# compiled program with NETLINK from Wolfram Mathematica?

Posted 7 years ago

Hello everyone! Can anyone explain some example how can you launch C# compiled program with NETLINK from Wolfram Mathematica with some description. Examples in internet focused on just use or launch some basic classes from c# System(System.Windows.Forms.Form) and etc. And none just gave example of basic c# program,such as 2+2 evaluated in C# and result can displayed in Mathematica's Notebook. Please help me with that. That will help me a lot.

This is my trying of do something,with errors... C# Program Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using Wolfram.NETLink;

class Program
{
static void Main(string[] args)
{
Console.WriteLine(Foo(2.0, 2.0).ToString());
Thread.Sleep(10000);
Console.WriteLine("yseee");
Console.Read();

}

public static double Foo(double x, double y)
{

IKernelLink link = StdLink.Link;
if (link != null)
{
link.Print("//inside foo");
if (x < 0)

link.Message("Foo::arg",
"The first argument to foo must be greater than or equal to 0.");
if (y < 0)

link.Message("Foo::arg",
"The second argument to foo must be greater than or equal to 0.");
}
return Math.Sqrt(x) * Math.Sqrt(y);
}
}

Wolfram Mathematica code

In[98]:= LoadedNETAssemblies[]
Out[98]= {NETAssembly[mscorlib,3],NETAssembly[InstallableNET,4],NETAssembly[Wolfram.NETLink,5],NETAssembly[System,6],NETAssembly[System.Windows.Forms,7],NETAssembly[System.Drawing,8],NETAssembly[ConsoleApplication2,2],NETAssembly[mscorlib.resources,9],NETAssembly[Accessibility,10]}
In[125]:= ConsoleApplication2`Program`Main[]
Out[125]= ConsoleApplication2`Program`Main[]
In[133]:= LoadNETAssembly["C:\\Users\\slash\\Desktop\\ConsoleApplication2\\ConsoleApplication2\\bin\\Release\\ConsoleApplication2.exe"]
Out[133]= NETAssembly[ConsoleApplication2,2]
In[135]:= LoadNETType["ConsoleApplication2`"]
During evaluation of In[135]:= NET::netexcptn: A .NET exception occurred: System.TypeLoadException: Type ConsoleApplication2` not found.
? Wolfram.NETLink.TypeLoader.GetType(String typeName, String assemblyName, Boolean throwOnError)
? Wolfram.NETLink.Internal.CallPacketHandler.loadType1(KernelLinkImpl ml).
During evaluation of In[135]:= LoadNETType::fail: .NET failed to load type ConsoleApplication2`.
Out[135]= $Failed

Thanks for some help.

Attachments:
POSTED BY: Ilyas Kadyrov

some years back I gave a talk at the annual conference on doing c# development in Mathematica, which might help you.

http://library.wolfram.com/infocenter/Conferences/7456/

POSTED BY: Frank Kampas
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract