nicko       2004/10/01 14:24:05

  Modified:    src/Core LocationInfo.cs
  Log:
  Added more checks for null in LocationInfo constructor
  
  Revision  Changes    Path
  1.5       +20 -8     logging-log4net/src/Core/LocationInfo.cs
  
  Index: LocationInfo.cs
  ===================================================================
  RCS file: /home/cvs/logging-log4net/src/Core/LocationInfo.cs,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- LocationInfo.cs   19 Sep 2004 17:52:54 -0000      1.4
  +++ LocationInfo.cs   1 Oct 2004 21:24:05 -0000       1.5
  @@ -88,7 +88,7 @@
                                        while (frameIndex < st.FrameCount)
                                        {
                                                StackFrame frame = 
st.GetFrame(frameIndex);
  -                                             if 
(frame.GetMethod().DeclaringType == callerStackBoundaryDeclaringType)
  +                                             if (frame != null && 
frame.GetMethod().DeclaringType == callerStackBoundaryDeclaringType)
                                                {
                                                        break;
                                                }
  @@ -99,7 +99,7 @@
                                        while (frameIndex < st.FrameCount)
                                        {
                                                StackFrame frame = 
st.GetFrame(frameIndex);
  -                                             if 
(frame.GetMethod().DeclaringType != callerStackBoundaryDeclaringType)
  +                                             if (frame != null && 
frame.GetMethod().DeclaringType != callerStackBoundaryDeclaringType)
                                                {
                                                        break;
                                                }
  @@ -111,12 +111,24 @@
                                                // now frameIndex is the first 
'user' caller frame
                                                StackFrame locationFrame = 
st.GetFrame(frameIndex);
   
  -                                             m_className = 
locationFrame.GetMethod().DeclaringType.FullName;
  -                                             m_fileName = 
locationFrame.GetFileName();
  -                                             m_lineNumber = 
locationFrame.GetFileLineNumber().ToString(System.Globalization.NumberFormatInfo.InvariantInfo);
  -                                             m_methodName =  
locationFrame.GetMethod().Name;
  -                                             m_fullInfo =  m_className + '.' 
+ m_methodName + '(' + 
  -                                                     m_fileName + ':' + 
m_lineNumber + ')';
  +                                             if (locationFrame != null)
  +                                             {
  +                                                     
System.Reflection.MethodBase method = locationFrame.GetMethod();
  +
  +                                                     if (method != null)
  +                                                     {
  +                                                             m_methodName =  
method.Name;
  +                                                             if 
(method.DeclaringType != null)
  +                                                             {
  +                                                                     
m_className = method.DeclaringType.FullName;
  +                                                             }
  +                                                     }
  +                                                     m_fileName = 
locationFrame.GetFileName();
  +                                                     m_lineNumber = 
locationFrame.GetFileLineNumber().ToString(System.Globalization.NumberFormatInfo.InvariantInfo);
  +
  +                                                     // Combine all location 
info
  +                                                     m_fullInfo =  
m_className + '.' + m_methodName + '(' + m_fileName + ':' + m_lineNumber + ')';
  +                                             }
                                        }
                                }
                                catch(System.Security.SecurityException)
  
  
  

Reply via email to