Morten Overgaard created LOG4NET-591:
----------------------------------------
Summary: Serializing LoggingEvent with null entries in Properties
throws exception
Key: LOG4NET-591
URL: https://issues.apache.org/jira/browse/LOG4NET-591
Project: Log4net
Issue Type: Bug
Components: Core
Affects Versions: 2.0.8
Reporter: Morten Overgaard
When serializing a PropertiesDictionary (as part of LoggingEvent) having null
values --> NullReference exception occurs
Â
This happens because of:
{code:java}
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);
}
}{code}
Suggestion (Not tested) :
{code:java}
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);
}
}
{code}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)