Unit3 LoadConfiguration() deprecated?

Jun 15, 2013 at 8:40 PM
I am new to Unity (version 3.0.1304.0) and am trying to set up my first web application with dependency injection. I have a web.config file that looks like this:
<?xml version="1.0" encoding="utf-8"?>
  For more information on how to configure your ASP.NET application, please visit
    <section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration"/>
<!--Irrelevant stuff omitted-->
  <unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
    <alias alias="ILogger" type="MyApp.ILogger, MyApp" />
    <namespace name="MyApp.Implementations" />
    <assembly name="MyApp" />
      <register type="ILogger" name="special" mapTo="SpecialLogger" />    

From the documentation, it says, "Adding a Unity configuration section to a configuration file neither create an actual container nor configures it. You must create a Unity container instance, read the configuration file, and load the configuration file information into the container. "

But the code it references:
IUnityContainer container = new UnityContainer();

seems to be incorrect...
Error   14  'Microsoft.Practices.Unity.UnityContainer' does not contain a definition for 'LoadConfiguration' and no extension method 'LoadConfiguration' accepting a first argument of type 'Microsoft.Practices.Unity.UnityContainer' could be found (are you missing a using directive or an assembly reference?) C:\Users\Brad\Documents\Visual Studio 2012\Projects\RebuildingSite\RebuildingSite\Global.asax.cs    34  23  RebuildingSite
Am I doing something wrong, or do I not need that method anymore?
Jun 15, 2013 at 9:00 PM
The LoadConfiguration is an extension method in the Microsoft.Practices.Unity.Configuration assembly. You need to add a reference to Microsoft.Practices.Unity.Configuration.dll.

Randy Levy
Enterprise Library support engineer
Support How-to
Jun 15, 2013 at 9:07 PM
That assembly doesn't seem to be present; I installed the Unity Framework with NuGet... do I need to get something else too?

Jun 15, 2013 at 9:18 PM
It should be downloaded from NuGet. The assembly is in the packages\Unity.3.0.1304.0\lib\Net45\ directory. It should be added to the project's References automatically.

Randy Levy
Enterprise Library support engineer
Support How-to
Jun 15, 2013 at 9:30 PM
I do see the reference to Microsoft.Practices.Unity.Configuration in the references section, but the compilation still fails. I tried uninstalling and reinstalling the Unity package from NuGet, and also tried adding an assembly reference by browsing. I still can't get the thing to compile.

I'd upload a screenshot if there were an easy way to do so...
Jun 15, 2013 at 10:10 PM
If it makes any difference, I'm using Visual Studio 2012 Express.
Jun 16, 2013 at 8:27 AM
Please, make sure there is a 'using Microsoft.Practices.Unity.Configuration;' wherever you're going to use that extension method.
Jun 16, 2013 at 2:34 PM
D'oh! That was simple! Thanks homelchenko, it works now. I wish VS would suggest using statements for extension methods...
Jun 16, 2013 at 3:24 PM
You're welcome, and tools like Resharper and others would have helped you, they do suggest such modifications