Geeks With Blogs
Fringe SharePoint Continued

I am working with a client to upgrade enterprise libraries in current code that they use. Specifically upgrading InfoPath 2003 Managed Code. Here are some things I learned while doing their upgrade:

1) Custom Sink = Custom Trace Listeners

      Enterprise library 1.1 or whatever the earlier version is has a Logging Block that allows you to create custom logging functionality. They were called Custom Sinks, well they are now called custom Trace Listeners in 4.1 and later. I can't say what 3.0 called them as I only started working with 4.1. This is not a huge deal except that the configuration documentation that was put together is not the same. Not only that but the old Custom Sink code overrides the following methods:

public override void Initialize(ConfigurationView configurationView)0

protected override void SendMessageCore(LogEntry logEntry){}

The new trace listener overrides the following:

public override void TraceData(System.Diagnostics.TraceEventCache eventCache, string source, System.Diagnostics.TraceEventType eventType, int id, object data)

public override void Write(string message) //along with several overloads

public override void WriteLine(string message) //along with several overloads

        If you are doing what I was doing, which was updating the Enterprise library to 4.1 or later then you will have issues with the new methods and inheriting class. You will have to inherit from "CustomTraceListener" and you can basically think of the old "Initialize" as the "Tracedata" method, and the old "SendMessageCore" as the Write and "Writeline", methods.

2) Attributes are Easier to Retrieve

      You might want to configure Attributes through the Configuration Files. The easiest process is to use the configuration tool that comes with the Enterprise libraries. The only reason I mention this is because I noticed a bunch of code in the old Custom Sink that seemed to retrieve the configuration information of the calling or using Application and get the Attributes. This is easier to retrieve than before. In the old "initialize" which is now , "TraceData", simply access the derived properties like so:

this.Attribibutes // this will give you an IDictionary<string, object> . All the configured attributes are there for you!

3) Inconsistent References will hurt you!

    I don't want to regurgitate what someone else already posted about but I used references in the GAC for the custom Trace Listener and then the calling application referenced the Signed assemblies or Unsigned assemblies somewhere else. Anyway, you will get errors like the following:

 "Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Common, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)"

Well this would appear that one of it's dependencies is not able to be loaded right? Well, maybe under the covers that's what is happening but the reason this happens is because you might be referencing different Enterprise library dll's. See this post for guidlines

Hope this helps someone!

Update: you might be asking why I didn't just use Enterprise Library 5.0? It is because Windows Server 2003 is not supported with the 5.0 version.

Posted on Monday, April 11, 2011 5:01 PM Development , BUGS | Back to top

Comments on this post: Enterprise Library 4.1 Fun!

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © juanlarios | Powered by: