title: Unity Bootstrapper from NuGet is throwing error on App_Start
body: <p>the Microsoft Unity Bootstrapper for Unity 3.0 is throwing an error on this line:</p>
  
  <pre><code>FilterProviders.Providers.Add(new UnityFilterAttributeFilterProvider(container));
  </code></pre>
  
  <p>with the following error:</p>
  
  <blockquote>
    <p>An exception of type 'System.ArrayTypeMismatchException' occurred in
    mscorlib.dll but was not handled in user code</p>
    
    <p>Additional information: Attempted to access an element as a type
    incompatible with the array.</p>
  </blockquote>
  
  <p>The entirety of the code is here and this was all pre-made and written by the bootstrapper downloaded from nuget.</p>
  
  <p><strong>Bootstrapper generated file App_Start/UnityMVCActivator.cs</strong></p>
  
  <pre><code>using System.Linq;
  using System.Web.Mvc;
  using Microsoft.Practices.Unity.Mvc;
  
  [assembly: WebActivatorEx.PreApplicationStartMethod(typeof(WebApplication.WebUI.App_Start.UnityWebActivator), "Start")]
  
  namespace WebApplication.WebUI.App_Start
  {
      /// &lt;summary&gt;Provides the bootstrapping for integrating Unity with ASP.NET MVC.&lt;/summary&gt;
      public static class UnityWebActivator
      {
          /// &lt;summary&gt;Integrates Unity when the application starts.&lt;/summary&gt;
          public static void Start() 
          {
              var container = UnityConfig.GetConfiguredContainer();
  
              FilterProviders.Providers.Remove(FilterProviders.Providers.OfType&lt;FilterAttributeFilterProvider&gt;().First());
              FilterProviders.Providers.Add(new UnityFilterAttributeFilterProvider(container));
  
              DependencyResolver.SetResolver(new UnityDependencyResolver(container));
  
              // TODO: Uncomment if you want to use PerRequestLifetimeManager
              // Microsoft.Web.Infrastructure.DynamicModuleHelper.DynamicModuleUtility.RegisterModule(typeof(UnityPerRequestHttpModule));
          }
      }
  }
  </code></pre>
  
  <p><strong>Bootstrapper generated file App_Start/UnityConfig.cs</strong></p>
  
  <pre><code>using System;
  using Microsoft.Practices.Unity;
  using Microsoft.Practices.Unity.Configuration;
  using WebApplication.Domain.Abstract;
  using WebApplication.Domain.Concrete;
  
  namespace WebApplication.WebUI.App_Start
  {
      /// &lt;summary&gt;
      /// Specifies the Unity configuration for the main container.
      /// &lt;/summary&gt;
      public class UnityConfig
      {
          #region Unity Container
          private static Lazy&lt;IUnityContainer&gt; container = new Lazy&lt;IUnityContainer&gt;(() =&gt;
          {
              var container = new UnityContainer();
              RegisterTypes(container);
              return container;
          });
  
          /// &lt;summary&gt;
          /// Gets the configured Unity container.
          /// &lt;/summary&gt;
          public static IUnityContainer GetConfiguredContainer()
          {
              return container.Value;
          }
          #endregion
  
          /// &lt;summary&gt;Registers the type mappings with the Unity container.&lt;/summary&gt;
          /// &lt;param name="container"&gt;The unity container to configure.&lt;/param&gt;
          /// &lt;remarks&gt;There is no need to register concrete types such as controllers or API controllers (unless you want to 
          /// change the defaults), as Unity allows resolving a concrete type even if it was not previously registered.&lt;/remarks&gt;
          public static void RegisterTypes(IUnityContainer container)
          {
              // NOTE: To load from web.config uncomment the line below. Make sure to add a Microsoft.Practices.Unity.Configuration to the using statements.
              //container.LoadConfiguration();
  
              // TODO: Register your types here
              //container.RegisterType&lt;IProductRepository, EFProductRepository&gt;();
          }
      }
  }
  </code></pre>
  
  <p>Any ideas?</p>
  
  <pre><code>#region Assembly Microsoft.Practices.Unity.Mvc.dll, v3.0.0.0
  // C:\Users\James\Documents\Visual Studio 2013\Projects\Application\packages\Unity.Mvc.3.0.1304.0\lib\Net45\Microsoft.Practices.Unity.Mvc.dll
  #endregion
  
  using Microsoft.Practices.Unity;
  using System.Collections.Generic;
  using System.Web.Mvc;
  
  namespace Microsoft.Practices.Unity.Mvc
  {
      // Summary:
      //     Defines a filter provider for filter attributes that support injection of
      //     Unity dependencies.
      public class UnityFilterAttributeFilterProvider : FilterAttributeFilterProvider
      {
          // Summary:
          //     Initializes a new instance of the Microsoft.Practices.Unity.Mvc.UnityFilterAttributeFilterProvider
          //     class.
          //
          // Parameters:
          //   container:
          //     The Microsoft.Practices.Unity.IUnityContainer that will be used to inject
          //     the filters.
          public UnityFilterAttributeFilterProvider(IUnityContainer container);
  
          // Summary:
          //     Gets a collection of custom action attributes, and injects them using a Unity
          //     container.
          //
          // Parameters:
          //   controllerContext:
          //     The controller context.
          //
          //   actionDescriptor:
          //     The action descriptor.
          //
          // Returns:
          //     A collection of custom action attributes.
          protected override IEnumerable&lt;FilterAttribute&gt; GetActionAttributes(ControllerContext controllerContext, ActionDescriptor actionDescriptor);
          //
          // Summary:
          //     Gets a collection of controller attributes, and injects them using a Unity
          //     container.
          //
          // Parameters:
          //   controllerContext:
          //     The controller context.
          //
          //   actionDescriptor:
          //     The action descriptor.
          //
          // Returns:
          //     A collection of controller attributes.
          protected override IEnumerable&lt;FilterAttribute&gt; GetControllerAttributes(ControllerContext controllerContext, ActionDescriptor actionDescriptor);
      }
  }
  </code></pre>
  
  <p>Packages installed by Unity bootstrapper</p>
  
  <pre><code>  &lt;package id="Unity" version="3.0.1304.1" targetFramework="net45" /&gt;
    &lt;package id="Unity.Mvc" version="3.0.1304.0" targetFramework="net45" /&gt;
    &lt;package id="WebActivatorEx" version="2.0.4" targetFramework="net45" /&gt;
  </code></pre>
  
  <p>Stack:</p>
  
  <pre><code>[ArrayTypeMismatchException: Attempted to access an element as a type incompatible with the array.]
     System.Collections.Generic.List`1.Insert(Int32 index, T item) +58
     System.Collections.ObjectModel.Collection`1.InsertItem(Int32 index, T item) +55
     System.Web.Mvc.FilterProviderCollection.InsertItem(Int32 index, IFilterProvider item) +47
     System.Collections.ObjectModel.Collection`1.Add(T item) +98
     WebApplication.WebUI.App_Start.UnityWebActivator.Start() in c:\Users\James\Documents\Visual Studio 2013\Projects\Application\WebApplication.WebUI\App_Start\UnityMvcActivator.cs:18
  
  [TargetInvocationException: Exception has been thrown by the target of an invocation.]
     System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) +0
     System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) +192
     System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +155
     System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) +19
     WebActivatorEx.BaseActivationMethodAttribute.InvokeMethod() +236
     WebActivatorEx.ActivationManager.RunActivationMethods(Boolean designerMode) +535
     WebActivatorEx.ActivationManager.RunPreStartMethods(Boolean designerMode) +48
     WebActivatorEx.ActivationManager.Run() +163
  
  [InvalidOperationException: The pre-application start initialization method Run on type WebActivatorEx.ActivationManager threw an exception with the following error message: Exception has been thrown by the target of an invocation..]
     System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection`1 methods, Func`1 setHostingEnvironmentCultures) +556
     System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +132
     System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean&amp; isRefAssemblyLoaded) +102
     System.Web.Compilation.BuildManager.ExecutePreAppStart() +153
     System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +516
  
  [HttpException (0x80004005): The pre-application start initialization method Run on type WebActivatorEx.ActivationManager threw an exception with the following error message: Exception has been thrown by the target of an invocation..]
     System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9882460
     System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
     System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
  </code></pre>