Question

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.

Was it helpful?

Solution

From the docs for Type.InvokeMember, the Exceptions section:

  • NotSupportedException
    The .NET Compact Framework does not currently support this method.

Seems pretty clear to me that it's not supported on .NET CF, which is what you're using.

I really hope that RetrurnString wouldn't work anyway, and that you'd want ReturnString.

You may have more luck fetching the method (Type.GetMethod) and then calling Invoke on the MethodInfo. I don't see the same restriction there...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top