Uploaded image for project: 'Log4net'
  1. Log4net
  2. LOG4NET-614

If LogicalThreadContext has a property with NULL value it causes an exception

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Duplicate
    • 2.0.8
    • 2.1.0
    • None
    • None

    Description

      I used to have the following inside the code:

      log4net.LogicalThreadContext.Properties["EventID"] = (int)idEvent;
      log.WarnFormat(format, p);
      log4net.LogicalThreadContext.Properties["EventID"] = null;
      

      It causes an exception in ReadOnlyPropertiesDictionary.GetObjectData(..)

      in the following code:

                          // If value is serializable then we add it to the list
      #if NETSTANDARD1_3
                      bool isSerializable = entryValue.GetType().GetTypeInfo().IsSerializable;
      #else
                          bool isSerializable = entryValue.GetType().IsSerializable;
      #endif
                          if (entryKey != null && entryValue != null && isSerializable)
                          {
                              // Store the keys as an Xml encoded local name as it may contain colons (':') 
                              // which are NOT escaped by the Xml Serialization framework.
                              // This must be a bug in the serialization framework as we cannot be expected
                              // to know the implementation details of all the possible transport layers.
                              info.AddValue(XmlConvert.EncodeLocalName(entryKey), entryValue);
                          }
                      }
      

      The source of the problem is clear : the check for entryValue != null should be done before isSerializable is initiated.

       

      As a workaround I changed my original code to be the following:

      log4net.LogicalThreadContext.Properties["EventID"] = (int)idEvent;
      log.WarnFormat(format, p);
      log4net.LogicalThreadContext.Properties.Remove("EventID");

      Attachments

        Issue Links

          Activity

            People

              nachbarslumpi Dominik Psenner
              ilyaba Ilya Badaev
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: