I created an object of a dynamically created type and i'm attempting to invoke a runtime loaded function.
The invoke call exceptions with: {System.ArgumentException: Object of type 'UserClasses.re_Constituent' cannot be converted to type 'UserClasses.re_Constituent'.}
(yes those 2 classes are the same)
the code for the class, and the code for the invoked function been previously generated and compiled as per http://ift.tt/2mqP9DJ
Does anyone know the source of the error?
The following code exceptions at the magicValue Invoke()
namespace myTest
{
internal class Program
{
Main(){
//pseudoCode
BuildTypes();
{Type myType,MethodInfo myMethod} = factory.getType("re_Constituent");
//actual code that exceptions
Node result = (Node) JSON.Deserialize(textstream,myType);
object magicValue = myMethodInfo.Invoke(null,new object[]{result});
}
}
namespace UserClasses
{
public abstract class Node
{}
}
inspecing when paused at the invoke line of code reveals:
myMethodInfo is: {System.Collections.Generic.List`1[UserClasses.Node] ConvertToCore(UserClasses.re_Constituent)}
the type of the parameter expected by the methodInfo is : "UserClasses.re_Constituent, dynamicGen_reApi_3, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"
the type passed to the JSON de-serializer (Jil) is listed as: "UserClasses.re_Constituent, dynamicGen_reApi_3, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"
result.GetType().AssemblyQualifiedName: "UserClasses.re_Constituent, dynamicGen_reApi_3, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"
re_Constituent is defined in a separate dynamically loaded dll.
namespace UserClasses
{
public class re_Constituent : Node
{
public string id;
... other fields
}
}
the code for the function is found in another runtime loaded dll:
namespace UserClasses
{
public static class MyExtensions
{
public static List<Node> ConvertToCore(this re_Constituent node)
{
return new List<Node>()
{
new Node(); // actual code is more complex here
};
}
}
}
I have verified that i haven't messed up my dynamic generation / loading by iterating all classes in all assemblies loaded, which shows nothing unusual:
foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
{
if(!assembly.GetName().Name.StartsWith("System"))
foreach (Type type in assembly.GetTypes())
{
if(type.FullName.Name.StartsWith("System"))
Console.WriteLine(type+":"+assembly.GetName().Name);
}
}
Aucun commentaire:
Enregistrer un commentaire