Unity error

Topics: Prism v2 - Silverlight 4
May 20, 2010 at 7:35 PM

 The current type, Microsoft.Practices.Unity.IUnityContainer, is an interface and cannot be constructed

what this means? by the way in one of my projects it kept asking me to add a reference to Unity 1.2 otherwise did not worked although I see stocktrader RI dont need that, whats the problem with this?

May 21, 2010 at 8:36 PM


That exception means that you are trying to instantiate an interface (IUnityContainer), and not the class that implements that interface, which in this case is UnityContainer. If you want to create a new container, you could write something like:

IUnityContainer container = new UnityContainer();

but not:

IUnityContainer container = new IUnityContainer();

As for the reference, in every project that you use the Unity Container, whether it is the shell or a module, you must add a reference to the Microsoft.Practices.Unity assembly. You can find that assembly in the LIB folder that comes with Prism. Inside the StockTrader RI, there are references to it in the shell and all its modules.

I hope you find this helpful.

Guido Leandro Maliandi

May 21, 2010 at 8:55 PM

Thanks Guido, however I did not solve the problem that way and it looks the instantiate interface error came from the previous error where it was always telling me to add 1.2 reference, once I did download and installed the 1.2 version and referened in my project, no more errors but now another error I don't remember poped up while loading the first module.

As a final measure, what I did was to copy all the CAL projects altogether to my solution (like it is with the StockTrader app) and magic happens using the unity 2.0 and these projects references instead of the dlls I got to run my project just fine, I don't know if someone else could confirm that using the dlls causes somewhow my errors and the workaround is to add the CAL projects references directly?


May 26, 2010 at 8:55 PM

I cannot get the Prism assemblies to build using Unity 2.0.  I have been trying for two days.  The problem is that the IUnityContainer.AddNewExtension<TExtension> no longer exists.  There is a generic method that is gone.  And there is no mention of it in any of the Unity 2.0 documentation.  They did detail some of the changes and deprecation on Unity 2.0, like the merge of ObjectBuilder2 into Unity and the deprecation of the Microsoft.Practices.ObjectBuilder2.BuildFailedException.  But there is no mention of the elimination of the AddNewExtension.  I pulled down the Unity 2.0 source code and confirmed the method is missing.  The Prism test projects use it extensively and they worn't build alog with the UnityBootstrapperExtension from the Composite.UnityExtensions.Desktop assembly.  I really need a Prism for Unity 2.0.  I have no choice but to keep trying to build it myself and the Unity 2.0 documentation has a hole in it.  What shall I do?

May 27, 2010 at 12:45 AM

Hi Joe,

We are about to drop Prism 2.2 which works with Unity 2, probably next week.  If you want, you can get a head start and look at change set 41709 or 42969 in the Source Code Area.


Jun 3, 2010 at 4:00 PM

Hi guys,

I though you would like to know that a couple of days ago a new drop of Prism 2.2 was just released . Therefore, you can find more information and download it from here instead of using the change sets.
Additionally, you can visit the Damian Schenkelman’s post where there are some interesting things in this new version and links to other posts.

I hope you can find this information useful.

Fernando Antivero

Jun 3, 2010 at 4:03 PM

Thanks fantivero yes it looks like the new drop solved the problems :)