# NETLink Problem with C# DLL

I am not getting the answers back from my DLL calls. Here are the simple C# functions. Not sure why I am not getting the correct answers. I can DLL import kernel32d.dll and can call getTickCount() just fine. Just not my home grown DLL. Any insight would be appreciated.

Thanks,

Phil

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace wpa1
{
public class Class1
{
public string func1(string strIn)
{
System.Console.WriteLine(strIn);
char[] letters = { 'A', 'B', 'C' };
string alphabet = new string(letters);
return alphabet;
}
public float add(float a, float b)
{
return a+b;
}
}
}


Here is the Mathematica

code:
Needs["NETLink"];
ReinstallNET["Force32Bit" -> True];
fullDllPath =
"c:\\users\\owner\\documents\\visual studio \
2015\\Projects\\wpa1\\wpa1\\bin\\Debug\\wpa1.dll";
"c:\\users\\owner\\documents\\visual studio \
2015\\Projects\\wpa1\\wpa1\\bin\\Debug"];
"float", {"float", "float"}];
func1 = DefineDLLFunction["func1", fullDllPath,
"float", {"float", "float"}];
obj = NETNew["wpa1.Class1"];
NETObjectQ[obj]
stback = obj.func1 ("hi there")
OwnValues[stback]


Here is the output in Mathematica:

True

"hi there" (NETLinkObjectsNETObject$192170795466753).Function[Null, If[NETLinkDLLPrivatecheckArgCount["func1", {##1}, 2], WolframNETLinkDynamicDLLNamespaceDLLWrapper2func1[##1], \$Failed], {HoldAll}]

{HoldPattern[stback] :>
"hi there" (NETLinkObjectsNETObject$192170795466753).Function[ Null, If[NETLinkDLLPrivatecheckArgCount["func1", {##1}, 2], WolframNETLinkDynamicDLLNamespaceDLLWrapper2func1[##1], \$Failed], {HoldAll}]}

{1.2 (NETLinkObjectsNETObject$192170795466753).add, 2.1 (NETLinkObjectsNETObject$192170795466753).add}


There are some minor errors that need to be corrected:

1. The main problem is that C# methods must be called using the syntax obj@Method[args]. The C#-looking expression obj.func1("hi there") will be interpreted as the (nonsensical) Mathematica expression Dot[obj, func1 * "hi there"].
2. The arguments to add must be passed as individual arguments instead of as a list.
3. There is no need to use DefineDLLFunction at all. LoadNETAssembly automatically defines all assembly types along with their members. DefineDLLFunction is used to define entrypoints in unmanaged DLLs, e.g. from C or C++. (Incidentally, but irrelevant to the present example: the argument and return type declarations of func1 were incorrect and the definition of the C# function add was being assigned to the symbol add1 instead of the symbol add which was used later.)

The following code applies all of these corrections:

LoadNETAssembly[fullDllPath];

obj = NETNew["wpa1.Class1"];

obj@func1["hi there"]
(* "ABC" *)

`