Sergey Shishkin

on agile software development

Enterprise Library: Couple of fixes

Working with Enterprise Library 2.0 I faced several issues. Two of them I describe here (fixes included 🙂 ).

1. I tried to add values in the Hashtable that is stored in the CallContext under the "EntLibLoggerContextItems" key to get these values populated to the LogEntry.ExtendedProperties dictionary. This is another long story why did not I use ContextItems.SetContextItem method instead of hacking it, and I will post about it separately 🙂 This functionality works fine – the Hashtable from the CallContext is being merged to the LogEntry.ExtendedProperties dictionary during processing the LogEntry by the LogWriter and ContextItems.ProcessContextItems method. Nevertheless, it has a flaw – instead of storing objects themselves, ContextItems.ProcessContextItems method calls ToString method on each object and stores the strings! It also does Base64 encoding for byte[] values but ToString looks like an ugly hack, since both LogEntry.ExtendedProperties dictionary and ContextItems.SetContextItem method accept not only strings but any objects.

File: Logging\ContextItems.cs, Line 87.

string itemValue = GetContextItemValue(entry.Value);
log.ExtendedProperties.Add(entry.Key.ToString(), itemValue);


log.ExtendedProperties.Add(entry.Key.ToString(), entry.Value);

2. The second problem I found in the QuickStart project – SQLConfigurationSource. I always got the ConfigurationException saying "Expected to find an element". Which element? No idea. Debugging and reflecting I found out that this exception is always thrown by the ConfigurationSection.DeserializeSection method expecting an element and getting a whitespace instead. So, I have asserted my developer’s right to have whitespaces as well as comments inside the configuration XML stored in the SQL Server 🙂 Here is the fix:

File: SQLConfigurationSource\Configuration\SqlConfigurationSystem.cs, Line 115

XmlReaderSettings settings = new XmlReaderSettings();
settings.CloseInput = true;


XmlReaderSettings settings = new XmlReaderSettings();
settings.CloseInput = true;
settings.IgnoreWhitespace = true;
settings.IgnoreComments = true;

That’s it!


Written by Sergey Shishkin

19.09.2006 at 14:48

Posted in Uncategorized

%d bloggers like this: