I am in the process of converting a web app from MVC3 to MVC4 for my client. So far, I have used this previous stackoverflow and these official steps during the conversion process. I would like to note that for step 4 within the official steps, I was not able to update to MVC4 by using NuGet. Instead, I had to download MVC4 from the Microsoft Download Center.
My issue is that when I run the web app (after "converting" to MVC4) I get the error:
The type name or alias IController could not be resolved. Please check your configuration file and verify this type name.
I know that IController is located in System.Web.MVC but I am not sure why the project cannot find it. I tried replicating this solution by adding both assembly and namespace tags for IController, but that didn't work. I did remove the old references to MVC, Helpers, and Webpages and replaced them with new references.
Below is code within the Web.config file. Note that I used ellipses when skipping over unrelated code.
Web.config (snippets)
<appSettings>
<add key="webpages:Version" value="2.0.0.0" />
<add key="PreserveLoginUrl" value="true" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Helpers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
...
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
<add namespace="Telerik.Web.Mvc" />
<add namespace="Telerik.Web.Mvc.UI" />
<add namespace="Infrastructure.MVC.Extensions" />
</namespaces>
</pages>
</system.web>
...
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.1" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<unity>
<!-- Controllers -->
<alias alias="IController" type="System.Web.Mvc.IController,System.Web.Mvc" />
...
<containers>
<container>
<!-- Controllers -->
<register type="IController" mapTo="TransactionController" name="TRANSACTION" />
<register type="IController" mapTo="ActionController" name="ACTION" />
<register type="IController" mapTo="TaskController" name="TASK" />
</container>
</containers>
The error comes from an InvalidOperationException which is thrown in the following code:
public class MvcApplication : System.Web.HttpApplication
{
...
private void ConfigureContainer()
{
var unityContainer = new UnityContainer();
var unityConfigSection = ConfigurationManager.GetSection("unity") as UnityConfigurationSection;
unityConfigSection.Configure(unityContainer); // exception thrown right here
ControllerBuilder.Current.SetControllerFactory(new UnityControllerFactory(unityContainer));
}
Also, within the Web.config file, I replaced the existing runtime tag with the one mentioned in step 7 of the official conversion guide (link in the beginning paragraph), but that didn't help as well.