Log4net
  1. Log4net
  2. LOG4NET-393

Using dynamic methods with log4net causes NullReferenceException in StackFrameItem

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Blocker Blocker
    • Resolution: Fixed
    • Affects Version/s: 1.2.12
    • Fix Version/s: 1.2.13
    • Component/s: Core
    • Labels:
      None
    • Environment:
      VS2012, Windows 7

      Description

      In our production code we use dynamic methods e.g. when using the factory pattern. We upgraded from 1.2.10 to 1.2.12 and encountered the following exception:

      log4net:ERROR An exception ocurred while retreiving stack frame information.
      System.NullReferenceException: Object reference not set to an instance of an object.
      at log4net.Core.StackFrameItem..ctor(StackFrame frame) in c:\Users\wilfred.dittmer\Documents\Visual Studio 2012\Projects\Log4netLambaExpressionTest\log4net-1.2.12-src\log4net-1.2.12\src\Core\StackFrameItem.cs:line 61

      I created a test project (attached) which shows the exception occuring.
      If the method is:

      {System.Object lambda_method(System.Runtime.CompilerServices.Closure)}

      then one cannot access the DeclaringType. The code then tries to get the FullName of the null value which causes the exception.

      According to: http://msdn.microsoft.com/en-us/library/system.reflection.emit.dynamicmethod.declaringtype.aspx

      "DynamicMethod.DeclaringType: Gets the type that declares the method, which is always null for dynamic methods."

      So it seems best to check if DeclaringType is null and if so leave the m_className set to 'NA'.

        Activity

        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Resolved Resolved
        27m 22s 1 Dominik Psenner 01/Oct/13 15:52
        Resolved Resolved Closed Closed
        16h 24m 1 Dominik Psenner 02/Oct/13 08:16
        Closed Closed Reopened Reopened
        35d 12h 15m 1 Stefan Bodewig 06/Nov/13 19:32
        Reopened Reopened Resolved Resolved
        18s 1 Stefan Bodewig 06/Nov/13 19:32
        Hide
        Dominik Psenner added a comment -

        The issue was fixed with 1.2.13. If the issue persists when you run 1.2.13 or later feel free to reopen the issue.

        Show
        Dominik Psenner added a comment - The issue was fixed with 1.2.13. If the issue persists when you run 1.2.13 or later feel free to reopen the issue.
        Hide
        Ezequiel Esteban Gonzalez added a comment -

        I had and have the same error

        Show
        Ezequiel Esteban Gonzalez added a comment - I had and have the same error
        Hide
        Stefan Bodewig added a comment -

        The vote to release 1.2.13 is currently underway and it will likely be released in afew days. When/if a Nuget package is created is outside of our control.

        Show
        Stefan Bodewig added a comment - The vote to release 1.2.13 is currently underway and it will likely be released in afew days. When/if a Nuget package is created is outside of our control.
        Show
        Dominik Psenner added a comment - http://logging.apache.org/log4net/release/faq.html#nuget
        Hide
        Philip Lee added a comment -

        I've just hit the same issue. It occurs in ASP.NET FormView when one of the attached methods is called, e.g. UpdateMethod="foo".
        When will the fix be available on NuGet?

        Show
        Philip Lee added a comment - I've just hit the same issue. It occurs in ASP.NET FormView when one of the attached methods is called, e.g. UpdateMethod="foo". When will the fix be available on NuGet?
        Stefan Bodewig made changes -
        Status Reopened [ 4 ] Resolved [ 5 ]
        Assignee Stefan Bodewig [ bodewig ]
        Fix Version/s 1.2.13 [ 12325554 ]
        Fix Version/s 1.3.0 [ 12317609 ]
        Resolution Fixed [ 1 ]
        Stefan Bodewig made changes -
        Resolution Fixed [ 1 ]
        Status Closed [ 6 ] Reopened [ 4 ]
        Assignee Dominik Psenner [ nachbarslumpi ] Stefan Bodewig [ bodewig ]
        Stefan Bodewig made changes -
        Fix Version/s 1.3 [ 12317609 ]
        Fix Version/s 1.2.13 [ 12324858 ]
        Dominik Psenner made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Hide
        Dominik Psenner added a comment -

        Thanks for trying it out! I'm closing the issue now.

        Show
        Dominik Psenner added a comment - Thanks for trying it out! I'm closing the issue now.
        W.R. Dittmer made changes -
        Description In our production code we use dynamic methods e.g. when using the factory pattern. We upgraded from 1.2.10 to 1.2.12 and encountered the following exception:

        log4net:ERROR An exception ocurred while retreiving stack frame information.
        System.NullReferenceException: Object reference not set to an instance of an object.
           at log4net.Core.StackFrameItem..ctor(StackFrame frame) in c:\Users\wilfred.dittmer\Documents\Visual Studio 2012\Projects\Log4netLambaExpressionTest\log4net-1.2.12-src\log4net-1.2.12\src\Core\StackFrameItem.cs:line 61

        I created a test project (attached) which shows the exception occuring.
        If the the method is: {System.Object lambda_method(System.Runtime.CompilerServices.Closure)}
        then one cannot access the DeclaringType. The code then tries to get the FullName of the null value which causes the exception.

        According to: http://msdn.microsoft.com/en-us/library/system.reflection.emit.dynamicmethod.declaringtype.aspx

        "DynamicMethod.DeclaringType: Gets the type that declares the method, which is always null for dynamic methods."

        So it seems best to check if DeclaringType is null and if so leave the m_className set to 'NA'.
        In our production code we use dynamic methods e.g. when using the factory pattern. We upgraded from 1.2.10 to 1.2.12 and encountered the following exception:

        log4net:ERROR An exception ocurred while retreiving stack frame information.
        System.NullReferenceException: Object reference not set to an instance of an object.
           at log4net.Core.StackFrameItem..ctor(StackFrame frame) in c:\Users\wilfred.dittmer\Documents\Visual Studio 2012\Projects\Log4netLambaExpressionTest\log4net-1.2.12-src\log4net-1.2.12\src\Core\StackFrameItem.cs:line 61

        I created a test project (attached) which shows the exception occuring.
        If the method is: {System.Object lambda_method(System.Runtime.CompilerServices.Closure)}
        then one cannot access the DeclaringType. The code then tries to get the FullName of the null value which causes the exception.

        According to: http://msdn.microsoft.com/en-us/library/system.reflection.emit.dynamicmethod.declaringtype.aspx

        "DynamicMethod.DeclaringType: Gets the type that declares the method, which is always null for dynamic methods."

        So it seems best to check if DeclaringType is null and if so leave the m_className set to 'NA'.
        Hide
        W.R. Dittmer added a comment - - edited

        Thanks, we'll wait for the next official release and stick to 1.2.10 in the mean time.

        Applied patch to the attached test project and it now runs.
        Applied patch to production code, which now also runs.

        Show
        W.R. Dittmer added a comment - - edited Thanks, we'll wait for the next official release and stick to 1.2.10 in the mean time. Applied patch to the attached test project and it now runs. Applied patch to production code, which now also runs.
        Dominik Psenner made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 1.2.13 [ 12324858 ]
        Resolution Fixed [ 1 ]
        Hide
        Dominik Psenner added a comment - - edited

        Fixed as of revision: 1528110

        Sorry for the inconvenience. Would you please try if the issue is fixed in svn?

        Show
        Dominik Psenner added a comment - - edited Fixed as of revision: 1528110 Sorry for the inconvenience. Would you please try if the issue is fixed in svn?
        Dominik Psenner made changes -
        Assignee Dominik Psenner [ nachbarslumpi ]
        Hide
        Dominik Psenner added a comment -

        Gotcha, I'm looking into this right now.

        Show
        Dominik Psenner added a comment - Gotcha, I'm looking into this right now.
        W.R. Dittmer made changes -
        Description In our production code we use dynamic methods e.g. when using the factory pattern. We upgraded from 1.2.10 to 1.2.12 and encountered the following exception:

        log4net:ERROR An exception ocurred while retreiving stack frame information.
        System.NullReferenceException: Object reference not set to an instance of an object.
           at log4net.Core.StackFrameItem..ctor(StackFrame frame) in c:\Users\wilfred.dittmer\Documents\Visual Studio 2012\Projects\Log4netLambaExpressionTest\log4net-1.2.12-src\log4net-1.2.12\src\Core\StackFrameItem.cs:line 61

        I created a test project (attached) which shows the exception occuring.
        If the the method is:: {System.Object lambda_method(System.Runtime.CompilerServices.Closure)}
        then one cannot access the DeclaringType. The code then tries to get the FullName of the null value which causes the exception.

        According to: http://msdn.microsoft.com/en-us/library/system.reflection.emit.dynamicmethod.declaringtype.aspx

        "DynamicMethod.DeclaringType: Gets the type that declares the method, which is always null for dynamic methods."

        So it seems best to check if DeclaringType is null and if so leave the m_className set to 'NA'.
        In our production code we use dynamic methods e.g. when using the factory pattern. We upgraded from 1.2.10 to 1.2.12 and encountered the following exception:

        log4net:ERROR An exception ocurred while retreiving stack frame information.
        System.NullReferenceException: Object reference not set to an instance of an object.
           at log4net.Core.StackFrameItem..ctor(StackFrame frame) in c:\Users\wilfred.dittmer\Documents\Visual Studio 2012\Projects\Log4netLambaExpressionTest\log4net-1.2.12-src\log4net-1.2.12\src\Core\StackFrameItem.cs:line 61

        I created a test project (attached) which shows the exception occuring.
        If the the method is: {System.Object lambda_method(System.Runtime.CompilerServices.Closure)}
        then one cannot access the DeclaringType. The code then tries to get the FullName of the null value which causes the exception.

        According to: http://msdn.microsoft.com/en-us/library/system.reflection.emit.dynamicmethod.declaringtype.aspx

        "DynamicMethod.DeclaringType: Gets the type that declares the method, which is always null for dynamic methods."

        So it seems best to check if DeclaringType is null and if so leave the m_className set to 'NA'.
        W.R. Dittmer made changes -
        Description In our production code we use dynamic methods e.g. when using the factory pattern. We upgraded from 1.2.10 to 1.2.12 and encountered the following exception:

        log4net:ERROR An exception ocurred while retreiving stack frame information.
        System.NullReferenceException: Object reference not set to an instance of an obj
        ect.
           at log4net.Core.StackFrameItem..ctor(StackFrame frame) in c:\Users\wilfred.dittmer\Documents\Visual Studio 2012\Projects\Log4netLambaExpressionTest\log4net-1
        .2.12-src\log4net-1.2.12\src\Core\StackFrameItem.cs:line 61

        I created a test project (attached) which shows the exception occuring.
        If the the method is:: {System.Object lambda_method(System.Runtime.CompilerServices.Closure)}
        then one cannot access the DeclaringType. The code then tries to get the FullName of the null value which causes the exception.

        According to: http://msdn.microsoft.com/en-us/library/system.reflection.emit.dynamicmethod.declaringtype.aspx

        "DynamicMethod.DeclaringType: Gets the type that declares the method, which is always null for dynamic methods."

        So it seems best to check if DeclaringType is null and if so leave the m_className set to 'NA'.
        In our production code we use dynamic methods e.g. when using the factory pattern. We upgraded from 1.2.10 to 1.2.12 and encountered the following exception:

        log4net:ERROR An exception ocurred while retreiving stack frame information.
        System.NullReferenceException: Object reference not set to an instance of an object.
           at log4net.Core.StackFrameItem..ctor(StackFrame frame) in c:\Users\wilfred.dittmer\Documents\Visual Studio 2012\Projects\Log4netLambaExpressionTest\log4net-1.2.12-src\log4net-1.2.12\src\Core\StackFrameItem.cs:line 61

        I created a test project (attached) which shows the exception occuring.
        If the the method is:: {System.Object lambda_method(System.Runtime.CompilerServices.Closure)}
        then one cannot access the DeclaringType. The code then tries to get the FullName of the null value which causes the exception.

        According to: http://msdn.microsoft.com/en-us/library/system.reflection.emit.dynamicmethod.declaringtype.aspx

        "DynamicMethod.DeclaringType: Gets the type that declares the method, which is always null for dynamic methods."

        So it seems best to check if DeclaringType is null and if so leave the m_className set to 'NA'.
        W.R. Dittmer made changes -
        Description In our production code we use dynamic methods e.g. when using the factory pattern. We upgraded from 1.2.10 to 1.2.12 and encountered the following exception:

        log4net:ERROR An exception ocurred while retreiving stack frame information.
        System.NullReferenceException: Object reference not set to an instance of an obj
        ect.
           at log4net.Core.StackFrameItem..ctor(StackFrame frame) in c:\Users\wilfred.dittmer\Documents\Visual Studio 2012\Projects\Log4netLambaExpressionTest\log4net-1
        .2.12-src\log4net-1.2.12\src\Core\StackFrameItem.cs:line 61

        I created a test project (attached) which shows the exception occuring.
        If the the method is:: {System.Object lambda_method(System.Runtime.CompilerServices.Closure)}
        the one cannot access the DeclaringType. The code then tries to get the FullName of the null value which causes the exception.

        According to: http://msdn.microsoft.com/en-us/library/system.reflection.emit.dynamicmethod.declaringtype.aspx

        "DynamicMethod.DeclaringType: Gets the type that declares the method, which is always null for dynamic methods."

        So it seems best to check if DeclaringType is null and if so leave the m_className set to 'NA'.
        In our production code we use dynamic methods e.g. when using the factory pattern. We upgraded from 1.2.10 to 1.2.12 and encountered the following exception:

        log4net:ERROR An exception ocurred while retreiving stack frame information.
        System.NullReferenceException: Object reference not set to an instance of an obj
        ect.
           at log4net.Core.StackFrameItem..ctor(StackFrame frame) in c:\Users\wilfred.dittmer\Documents\Visual Studio 2012\Projects\Log4netLambaExpressionTest\log4net-1
        .2.12-src\log4net-1.2.12\src\Core\StackFrameItem.cs:line 61

        I created a test project (attached) which shows the exception occuring.
        If the the method is:: {System.Object lambda_method(System.Runtime.CompilerServices.Closure)}
        then one cannot access the DeclaringType. The code then tries to get the FullName of the null value which causes the exception.

        According to: http://msdn.microsoft.com/en-us/library/system.reflection.emit.dynamicmethod.declaringtype.aspx

        "DynamicMethod.DeclaringType: Gets the type that declares the method, which is always null for dynamic methods."

        So it seems best to check if DeclaringType is null and if so leave the m_className set to 'NA'.
        W.R. Dittmer made changes -
        Field Original Value New Value
        Attachment Log4netLambaExpressionTest.zip [ 12606108 ]
        W.R. Dittmer created issue -

          People

          • Assignee:
            Unassigned
            Reporter:
            W.R. Dittmer
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development