Enterprise Library Tips & Tricks

Tweet

Last week, Microsoft’s Patterns & Practices team released Patch 2554 for the Enterprise Library 2.0. The main point of this patch is to allow one to use the library in partial trust mode—which is a common scenario with web applications in these dangerous days.

I have been using the libraries quite a while, so I thought I would share some tips and tricks about using the code that I found were not particularly well documented nor advertised.

Trick #1: Get the Libs, Man

There are two current versions of the Enterprise Library: Version 1.1 (aka June 2005) for .NET 1.1 and Version 2.0 (aka January 2006) for .NET 2.0. Download as appropriate & desired.

Trick #2: Do the Labs, Man

The first time I looked at the documentation, I was wondering what the hell I got into. Fortunately I stumbled on the Enterprise Library Hands-On Labs (available for 1.1 and 2.0). I found they were quite well written quickly gave the student the ability to make use of the major features of the library.

Trick #3: Remember to Build for Release

The Enterprise Library is, interestingly enough, released only as source code with an installer. This installer does provide a handy “Build the Enterprise Library” checkbox. But there is a hidden gotcha—it builds the library using the DEBUG, not RELEASE, build setting. This means the code is not fully optimized for production use.

Now, if you are including the projects and compiling them with your solution things will work out just fine. But I, myself, prefer to just statically include the compiled assemblies as I don’t really need to worry about the internals of said library.

In any case, building the library properly is a two step process. First, you must run the release build script. Then you must run the script to copy the assemblies. Presuming one has installed the library to c:projectsEntLib, you will need to fire up a command window and run the following commands in that folder:

c:ProjectsEntLibBuildLibrary Release
c:ProjectsEntLibCopyAssemblies Release

[Note that the sources for Version 1.1 are in the [InstallFolder]src folder, so you will have to go there to find the scripts. Also note that, for Version 1.1, Visual Studio .NET 2003 must be installed for the build script to function.]

After running this, all necessary dlls (and xml documentation) will be avaliable in the bin folder of your enterprise library directory.

Trick #4: InstallUtil

This trick really applies to version 1.1. By default it fires off a number of performance counters and writes to the event log. Now, this is generally not a problem in development. But as soon as one moves the application to the staging server, one gets a nasty “Cannot write to registry” error.

There are two ways around this. First, one can modify the build options so that it does not use performance counters. I have, admittedly, never got this to work successfully. But then again I did not try particularly hard. And I happen to like having performance counters available.

The other option is to use .NET’s InstallUtil.exe utility to register the assemblies. To do so, you need to fire up a trusty command line window and run the following command for each of the library’s assemblies you are using:

C:WINDOWSMicrosoft.NETFrameworkv1.1.4322InstallUtil.exe c:MyAppFolderbinEnterpriseLibraryAssembly.dll

Replacing the path to the assembly as appropriate.

Free book: Jump Start HTML5 Basics

Grab a free copy of one our latest ebooks! Packed with hints and tips on HTML5's most powerful new features.

  • Negrolend

    Please I need your advice.
    I have vital issue of blocking pop ups and banners, while surfing the Web.
    I tried several programs – some do not provide satisfy block results, some are not handy to use. Did anyone were interested in that kind of problem and can you advise something?
    Please, support your suggestions with facts.

  • Pingback: Technical Related Notes » Blog Archive » links for 2006-08-01

  • watherton

    Hi Wyatt, some great tips there, some i am sure I will use.

    Do you know of or heard of any books explaining the workings and application of EL 2006 will be available, normally there is a truck load of authors that publish before major MS releases, but I can not find any that are out there yet.

    Cheers

    Wayne

  • wwb_99

    @Wayne:

    The enterprise library is not a “normal” ms application, such as Visual Studio or Sharepoint. It is a library for use within applications. And as such does not attract quite the same attention as the commercial packages nor the same publishing buzz. Nor does it particularly deal with buzzword-worthy, web 2.0 phenomenon such as ajax–so no pre-release book craze like Atlas has seen.

    Still, I did stumble upon two books (a and b). I have not read either so I cannot make a recommendation either way.

    I would recommend checking out the Library’s bundled documentation which actually goes a long way into explaining its internals. In addition, I would work through the quickstarts and labs to get your head around things. There is also the GotDotNet Patterns & Practices workspace which tends to be the bleeding edge of things.

    I should note I have never been a “read a book” but rather a “just sit down and code” type of learner.

    Hope this helps.

  • watherton

    @wwb_99:

    Thanks for the tips.

  • Marian

    Thank you for making the effort of sharing your tricks. We now have something to start with.