启动时参数计数不匹配

时间:2016-10-03 14:22:17

标签: c# asp.net-mvc asp.net-identity startup

我在Startup.cs代码执行完毕之后才得到参数计数不匹配。如果退出Startup类失败。但我无法弄清楚代码的下一步。它不会发给我的控制器。

 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);
        }
    }

堆栈追踪:

[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

我刚刚注册了我的ASP.NET.Identity经理,然后我收到了这个错误。

任何人都知道为什么?

2 个答案:

答案 0 :(得分:3)

在简单的进样器中,删除WebActivator程序集

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
    {
    }

它看起来像上面的代码

答案 1 :(得分:2)

在您的注射器的引擎盖下,它被称为

System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)

有两个参数,第一个是调用方法的目标实例,第二个是方法参数数组。

我们不知道您的上下文,但问题来自方法参数数组。不匹配发生在那里。参数计数不匹配。

使用debug并查看发生的位置并根据您的具体情况进行修复。