Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Duplicate
-
2.0.8
-
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
- duplicates
-
LOG4NET-581 NullReferenceException from log4net.Util.ReadOnlyPropertiesDictionary.GetObjectData
- Resolved