Invokemethod and static variables

J

julien

Hello,
I have an assembly with a static variable:
private static readonly ILog log4net = LogManager.GetLogger(typeof(Core));

In one of the methods, I use this variable:
private void myMethod()
{
...
log4net.Debug("something to log");
...
}


In one of my NUnit test, I create an instance for this assembly, and
call Mymethod:

Assembly asm = Assembly.LoadFrom("assembly.exe");
Type typeAssembly = asm.GetType("MyType");

object core = Activator.CreateInstance(typeAssembly, true);

typeAssembly.InvokeMember("myMethod",BindingFlags.InvokeMethod |
BindingFlags.NonPublic | BindingFlags.Instance, null, core, null);

System.Reflection.TargetInvocationException : An exception was raised by
the target of a call
----> System.StackOverflowException : A System.StackOverflowException
exception was raised at
System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj,
BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo
culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess)
at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj,
BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo
culture, Boolean verifyAccess) at
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, Binding
Flags invokeAttr, Binder binder, Object[] parameters, CultureInfo
culture) at System.RuntimeType.InvokeMember(String name, BindingFlags
invokeAttr, Binder binder, Object target, Object[] args,
ParameterModifier[] modifiers, CultureInfo culture, String[]
namedParameters)

Exception not handled : StackOverflowException.

I don't have this error when I don't use the late binding, so log4net is
working (and I can actually the logs on the screen).


Thank you
Julien
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top