Adventures on the edge

Learning new development technologies (2015 - 2018)
    "When living on the bleeding edge - you sometimes have to bleed" -BillKrat

How to load Unity IOC configuration from app.config

If you follow the available documentation on MSDN, or on various internet sites such as StackOverflow, you’ll find the app.config configuration in figure 1; it is wrong and you’ll receive the following error:

An error occurred creating the configuration section header for unity: could not load file or assembly ‘Microsoft.Practices.Unity.Configuration…’
Adventures on the edge

This sent me for a loop as I generally use the Microsoft packages for Unity, but decided that for my open source contact manager application (http://github.com/billkrat/contact-manager) that I will use the latest NuGet version and was surprised when I encountered the error shown in figure 1.

In hindsight it was a rather obvious issue/fix – but I blog about it because if you’re like me you could waste time on this because there is a blatant violation of development standards that forces us to “think outside of the box”, the “standards” box that is.   The namespace does not match the assembly name, reference figure 3.

Since I didn’t add the namespaces manually (I used NuGet) I didn’t realize this until I had to start digging in deep.

Once you update the assembly in the configuration file to reflect Unity.Configuration (as shown in figure 2) you can then follow the documentation available at the Microsoft site for “The Unity Configuration Schema”; it has comprehensive documentation – you can also reference my above GitHub open source project for examples as I use it throughout the application.

UnityNamespace

Figure 1 following documentation generates error

UnityNamespace-fixed

Figure 2 proper configuration for section

UnityNamespace-NuGet

Figure 3 mismatch between assembly name and its namespaces

Comments are closed