I am attempting to convert established code into a .dll which will be able to be loaded as required by the main program. The .dll does not require any input parameters from the main program and is intended to only return a string value. My primary resource has been this answer.
The dll code is structured:
namespace DLL
{
class DLLClass
{
public string PublicString(string OutputString)
{
// ... existing code ...
return OutputString;
}
}
}
The main program attempts to load the .dll, execute the logic, and retrieve the returned string for display in the console:
static void Main()
{
var DLLPath = new FileInfo("DLL.dll");
Assembly assembly = Assembly.LoadFile(DLLPath.FullName);
Type t = assembly.GetType("DLL.DLLClass");
object obj = Activator.CreateInstance(t);
MethodInfo method = t.GetMethod("PublicString");
string TargetString = (string)method.Invoke(obj, null);
Console.WriteLine("End of dll");
Console.WriteLine(TargetString);
Console.ReadLine();
}
This method presently fails as a TargetParameterCountException ("Parameter count mismatch") occurs at the .Invoke line. The debug information indicates the OutputString remains null at the time of the exception, meaning the code within the .dll does not appear to have run yet.
Thank you in advance for any assistance in this matter.