Quantcast
Channel: Common Language Runtime Internals and Architecture forum
Viewing all articles
Browse latest Browse all 1710

Error invoking constructor using reflection

$
0
0

I have 

public class A{}
public class B
    {
        A a;
        public B(A a)
        {
            this.a =a;
        }
}

Now i am trying to invoke constructor of B using reflection.

A a = new A();
var type = typeof(B);
var ctr = type.GetConstructor(new []{typeof(A)});
var instance = ctr.Invoke(new Object[] { a });
Console.Out.Write(null != instance);

This runs fine in my local system however failing in the build server(using NAnt) and giving me an exception

System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.
  ----> System.InvalidProgramException : Common Language Runtime detected an invalid program.
at System.RuntimeMethodHandle._InvokeConstructor(Object[] args, SignatureStruct& signature, IntPtr declaringType)
at System.RuntimeMethodHandle.InvokeConstructor(Object[] args, SignatureStruct signature, RuntimeTypeHandle declaringType)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.ConstructorInfo.Invoke(Object[] parameters)
at Program..ctr(A a) in Program.cs:line 20
--InvalidProgramException

Any idea whats going wrong here and how can i debug further ?


Viewing all articles
Browse latest Browse all 1710

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>