I’m using a .NET CF 3.5 to create a dll and invoke a public member of the DLL from the exe.
The Dll code is given below :
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
namespace DllPoc
{
public class DllCheck
{
public String ReturnString()
{
return "Hello DLL";
}
}
}
and the exe code is:
public partial class Form1 : Form
{
String _AppPath;
String _AppImage;
String _AppName;
public Form1()
{
InitializeComponent();
//ReadAppLoaderXML();
//StartApp();
Assembly assembly = Assembly.LoadFrom("\\test\\DllPoc.dll");
Type type = assembly.GetType("DllPoc.DllCheck");
var obj = Activator.CreateInstance(type);
String s = (String)type.InvokeMember("RetrurnString",
BindingFlags.InvokeMethod | BindingFlags.Instance |
BindingFlags.Public, null, obj, null);
MessageBox.Show(s);
// Exit
Application.Exit();
}
}
On execution of the line:
String s = (String)type.InvokeMember("RetrurnString",
BindingFlags.InvokeMethod | BindingFlags.Instance |
BindingFlags.Public, null, obj, null);
NotSupportedException is thrown.
Is this the correct procedure?
Thanks.
From the docs for
Type.InvokeMember, the Exceptions section:Seems pretty clear to me that it’s not supported on .NET CF, which is what you’re using.
I really hope that
RetrurnStringwouldn’t work anyway, and that you’d wantReturnString.You may have more luck fetching the method (
Type.GetMethod) and then callingInvokeon theMethodInfo. I don’t see the same restriction there…