Tuesday, March 16, 2010

Could not load file or assembly 'Microsoft.Practices.ObjectBuilder2

Today this issue was driving me nuts.

My application using EnterpriseLibrary for exceptionhandling and logging was running smoothly on my XP-machine, but when the application was run via the Visual Studio solution on my Windows Server 2008 VPC (yes, SharePoint development indeed) it crashed with the following exception throw upon the first call to
Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write(LogEntry)

Could not load file or assembly 'Microsoft.Practices.ObjectBuilder2, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

The Microsoft.Practices.ObjectBuilder2 was not referenced from the Visual Studio project and neither deployed to the GAC on the XP-machine, but still seemed to work just fine there anyway.

Why?

Well, it seems like the assembly refering the missing ObjectBuilder2 assembly (Microsoft.Practices.EnterpriseLibrary.Logging.dll) loaded the ObjectBuilder2 assembly from the EnterpriseLibrary installation folder (C:\Program Files\Microsoft Enterprise Library 4.0 - May 2008\Bin), but since the Windows Server 2008 machine was missing the Microsoft Enterprise Library .msi installation it did not have any of those assemblies under C:\Program Files\Microsoft Enterprise Library 4.0...

Glad I run into this problem while still developing the app...

So the solution was simply to copy the C:\Program Files\Microsoft Enterprise Library 4.0 - May 2008\Bin\Microsoft.Practices.ObjectBuilder2.dll on my XP-machine to the "Libs" folder of my application where all 3:rd party assemblies that my application uses are stored, and then add a reference to it in my Visual Studio project.

Simple as that...

And the soundtrack for this post?
http://www.deezer.com/en/#music/black-flag/nervous-breakdown-165204

4 comments:

  1. Thanks for posting this! This error was driving me crazy. Thanks again.

    ReplyDelete
  2. Thanks, replacing the dll's solved my problem.

    ReplyDelete
  3. Thanks for the tip! Another one rides the bus!

    ReplyDelete
  4. Got me out of a sticky situation. Thanks for the help.

    ReplyDelete