Invokemethod and static variables

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • julien

    Invokemethod and static variables

    Hello,
    I have an assembly with a static variable:
    private static readonly ILog log4net = LogManager.GetL ogger(typeof(Co re));

    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.LoadFr om("assembly.ex e");
    Type typeAssembly = asm.GetType("My Type");

    object core = Activator.Creat eInstance(typeA ssembly, true);

    typeAssembly.In vokeMember("myM ethod",BindingF lags.InvokeMeth od |
    BindingFlags.No nPublic | BindingFlags.In stance, null, core, null);

    System.Reflecti on.TargetInvoca tionException : An exception was raised by
    the target of a call
    ----> System.StackOve rflowException : A System.StackOve rflowException
    exception was raised at
    System.Reflecti on.RuntimeMetho dInfo.InternalI nvoke(Object obj,
    BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo
    culture, Boolean isBinderDefault , Assembly caller, Boolean verifyAccess)
    at System.Reflecti on.RuntimeMetho dInfo.InternalI nvoke(Object obj,
    BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo
    culture, Boolean verifyAccess) at
    System.Reflecti on.RuntimeMetho dInfo.Invoke(Ob ject obj, Binding
    Flags invokeAttr, Binder binder, Object[] parameters, CultureInfo
    culture) at System.RuntimeT ype.InvokeMembe r(String name, BindingFlags
    invokeAttr, Binder binder, Object target, Object[] args,
    ParameterModifi er[] modifiers, CultureInfo culture, String[]
    namedParameters )

    Exception not handled : StackOverflowEx ception.

    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
  • Jon Skeet [C# MVP]

    #2
    Re: Invokemethod and static variables

    julien <julien@sobrier .net> wrote:

    <snip>
    [color=blue]
    > Exception not handled : StackOverflowEx ception.
    >
    > 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).[/color]

    Could you post a short but complete program which demonstrates the
    problem?

    See http://www.pobox.com/~skeet/csharp/complete.html for details of
    what I mean by that.

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    • julien

      #3
      Re: Invokemethod and static variables

      Jon Skeet [C# MVP] a écrit :[color=blue]
      > julien <julien@sobrier .net> wrote:
      >
      > <snip>
      > [color=green]
      >>Exception not handled : StackOverflowEx ception.
      >>
      >>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).[/color]
      >
      >
      > Could you post a short but complete program which demonstrates the
      > problem?
      >
      > See http://www.pobox.com/~skeet/csharp/complete.html for details of
      > what I mean by that.
      > [/color]

      Actually, even though commenting the line with the static variable made
      the StackIverflow to dissapear, the problem was somewhere else!

      Thank you
      Julien

      Comment

      Working...