Gallery

Compile errors while migrating from Unity 1.2 to version 2.0

While migrating project from Unity version 1.2 to version 2.0 I came across several compiler errors like below:

c.Resolve<ILogger>();

with following error message:

The non-generic method 'Microsoft.Practices.Unity.UnityContainer.Resolve(System.Type, string, params Microsoft.Practices.Unity.ResolverOverride[])' cannot be used with type arguments

It happened because in the code we were specifying types with a namespace like below:

Microsoft.Practices.Unity.UnityContainer c = new Microsoft.Practices.Unity.UnityContainer();

and there was no using directive aliasing the Microsoft.Practices.Unity namespace. Because the new version of Unity defines those generic methods (and many more) as extension methods, the following using statement is required:

using Microsoft.Practices.Unity;

Fortunately, this time the migration was rather easy and after updating using section in several classes we were good to go.

You can read more about Extension Methods at following address
http://msdn.microsoft.com/en-us/library/bb383977.aspx

You can read more about Unity Container methods at following address
http://msdn.microsoft.com/en-us/library/microsoft.practices.unity.unitycontainer_methods(PandP.20).aspx

You can read more about Unity Container methods at following address
http://msdn.microsoft.com/en-us/library/ff660929(PandP.20).aspx

Advertisements

One thought on “Compile errors while migrating from Unity 1.2 to version 2.0

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s