Search code examples
c#asp.net-mvcasp.net-identitystartup

Parameter count mismatch on startup


I'm getting a parameter count mismatch except right after the Startup.cs code has finished executing. If fails on exit of the Startup class. But I can't figure out where the code goes next. It doesnt go to my controller.

 public partial class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            var container = SimpleInjectorInitializer.Initialize(app);
            ConfigureAuth(app, container);
        }
    }

Startup.Auth

public partial class Startup
    {
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app, Container container)
        {
            app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
            app.CreatePerOwinContext(() => container.GetInstance<ApplicationUserManager>());
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath = new PathString("/Account/Login"),
                Provider = new CookieAuthenticationProvider
                {
                    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
                        validateInterval: TimeSpan.FromMinutes(30),
                        regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
                }
            });
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
            app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));
            app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);
        }
    }

Stack trace:

[TargetParameterCountException: Parameter count mismatch.]
   System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +11414282
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +54
   System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) +21
   WebActivator.BaseActivationMethodAttribute.InvokeMethod() +236
   WebActivator.ActivationManager.RunActivationMethods() +370
   WebActivator.ActivationManager.RunPostStartMethods() +41
   WebActivator.StartMethodCallingModule.Init(HttpApplication context) +125
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +534
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +352
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296

[HttpException (0x80004005): Parameter count mismatch.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9947380
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +261

I've just finished registering my ASP.NET.Identity managers and then I receive this error.

Anyone know why?


Solution

  • In simple injector remove the WebActivator Assembly

    namespace WebApplication1.App_Start
    {
        using System.Reflection;
        using System.Web.Mvc;
    
        using SimpleInjector;
        using SimpleInjector.Extensions;
        using SimpleInjector.Integration.Web;
        using SimpleInjector.Integration.Web.Mvc;
        using Owin;
        using Models;
        using Microsoft.AspNet.Identity;
        using Microsoft.AspNet.Identity.EntityFramework;
        using Microsoft.Owin.Security.DataProtection;
        using Microsoft.AspNet.Identity.Owin;
        using Microsoft.Owin.Security;
        using SimpleInjector.Advanced;
        using Microsoft.Owin;
        using System.Web;
        using System.Collections.Generic;
    
        public static class SimpleInjectorInitializer
        {
        }
    

    It wants to look like the above code