samedi 19 décembre 2015

Unable to receive structure array of dll in other dll through reflection C#

I tried to call a function in another dll through reflection which returns an array of structs. But at runtime this error occurs "Unable to convert first_dll.class1.mysturct[,] to second_dll.class1.mysturct[,]"

First dll:

/************  Ist dll ****************/
namespace first_dll
{
    class class1
    {
        public struct mystruct 
        {
            int a;
            byte b;
        };

        public static mystruct[,] function1(mystruct[,] parameter)
        {
            //manupluating structure array here and returning it
            return parameter;   
        }    
    }    
}

Second dll:

/******** Second dll *********/
namespace second_dll
{
    class class1
    {
        Methodinfo m; // global variable

        public struct mystruct
        {
            int a;    
            byte b;
        };

        public static void load_dll()
        {
            Assembly assembly = Assembly.Load(@"path of first_dll");    
            Type type = assembly.Gettype("first_dll.class1");
            m = type.Getmethod("function1");
        }

        public void function2()
        {
            mystruct[,] structure = new mystruct[10,10];

            //adding value to structure here
            mystruct[,] structure_returning;  // declaring structure to store retuning array;
            //error occur here
            structure_returning = m.Invoke(null,new object[] { structure } )   

        }
    }
}





Aucun commentaire:

Enregistrer un commentaire