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

Serializing LoggingEvent with null entries in Properties throws exception

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Critical
    • Resolution: Duplicate
    • Affects Version/s: 2.0.8
    • Fix Version/s: 2.1.0
    • Component/s: Core
    • Labels:

      Description

      When serializing a PropertiesDictionary (as part of LoggingEvent) having null values --> NullReference exception occurs

       

      This happens because of:

      public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
      {
       foreach (DictionaryEntry dictionaryEntry in this.InnerHashtable.Clone() as IDictionary)
       {
         string key = dictionaryEntry.Key as string;
         object obj = dictionaryEntry.Value;  // When dictionaryEntry.Value is null
       bool isSerializable = obj.GetType().IsSerializable; // NullReferenceException
       if (key != null && obj != null && isSerializable)
       info.AddValue(XmlConvert.EncodeLocalName(key), obj);
       }
       }

      Suggestion (Not tested) :

      public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
      {
      foreach (DictionaryEntry dictionaryEntry in this.InnerHashtable.Clone() as IDictionary)
      {
      string key = dictionaryEntry.Key as string;
      object obj = dictionaryEntry.Value;
      bool isSerializable = obj == null ? false :  obj.GetType().IsSerializable;
      if (key != null && obj != null && isSerializable)
      info.AddValue(XmlConvert.EncodeLocalName(key), obj);
      }
      }
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                overgaardmorten Morten Overgaard
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: