繁体   English   中英

VB.NET MVC重载解析失败,因为没有可访问的“创建”接受此数量的参数

[英]VB.NET MVC Overload resolution failed because no accessible 'Create' accepts this number of arguments

我正在将VB.NET MVC 5Identity 2.0一起使用

我一直在尝试将Startup.Auth配置为按请求自动使用ApplicationDbContext,CustomUserManager和CustomRoleManager的单个实例, 如本教程中所述

我的代码如下:(减去垃圾)

Public Sub ConfigureAuth(app As IAppBuilder)
    app.CreatePerOwinContext(ApplicationDbContext.Create)
    ' Error 135 Overload resolution failed because no accessible 'CreatePerOwinContext' can be called with these arguments:
    '   Extension method 'Public Function CreatePerOwinContext(Of T)(createCallback As System.Func(Of Microsoft.AspNet.Identity.Owin.IdentityFactoryOptions(Of T), Microsoft.Owin.IOwinContext, T)) As Owin.IAppBuilder' defined in 'Owin.AppBuilderExtensions': Data type(s) of the type parameter(s) cannot be inferred from these arguments. Specifying the data type(s) explicitly might correct this error.
    '   Extension method 'Public Function CreatePerOwinContext(Of T)(createCallback As System.Func(Of T)) As Owin.IAppBuilder' defined in 'Owin.AppBuilderExtensions': Data type(s) of the type parameter(s) cannot be inferred from these arguments. Specifying the data type(s) explicitly might correct this error.

    app.CreatePerOwinContext(Of CustomUserManager)(CustomUserManager.Create)
    ' Error 136 Overload resolution failed because no accessible 'Create' accepts this number of arguments.
    ....
End Sub

但是无论我做什么都接受这些错误

重载解析失败,因为没有可访问的“创建”接受此数量的参数。

我认为这与我用VB编写代码以及使用C#编写示例有关,尽管这使我感到恼火,但这是一个问题。 我的CustomUserManager是公共类,而Create方法是公共共享。

Public Shared Function Create(options As IdentityFactoryOptions(Of CustomUserManager), context As IOwinContext) As CustomUserManager
    Dim manager As CustomUserManager
    manager = New CustomUserManager(New CustomUserStore(context.Get(Of ApplicationDbContext)()))
    manager.UserValidator = New UserValidator(Of ApplicationUser, Integer)(manager)
    manager.PasswordValidator = New PasswordValidator() With {
        .RequiredLength = 6
    }
    manager.RegisterTwoFactorProvider("EmailCode",
        New EmailTokenProvider(Of ApplicationUser, Integer)() With {
            .Subject = "Security Code",
            .BodyFormat = "Your security code is: {0}"
        }
    )
    manager.EmailService = New EmailService()
    manager.SmsService = New SmsService()
    If Not options.DataProtectionProvider Is Nothing Then
        manager.UserTokenProvider = New DataProtectorTokenProvider(Of ApplicationUser, Integer)(options.DataProtectionProvider.Create("ASP.NET Identity"))
    End If
    Return manager
End Function

有任何想法吗? 非常感谢您的帮助,干杯。

尝试这个

Public Sub ConfigureAuth(app As IAppBuilder)
    app.CreatePerOwinContext(AddressOf ApplicationDbContext.Create)
End Sub

AddressOf运算符创建一个指向过程名称指定的函数的函数委托

链接1

LINK2

如果您已经使用Update 3更新了Visual Studio 2013,则其中包括所有身份信息,自定义用户管理器,角色管理器等。

使用MVC模板创建新项目,并使用Visual Studio 2013将“身份验证”选择为“个人用户帐户”。然后,您将创建与该示例已实现的所有代码相同的所有代码。 您可以使用该类和实现来解决自定义用户管理器的问题。

检查选单App_Start >> IdentityConfig.vb

我在您的代码中只能看到的是,您使用整数作为Id,而不是字符串。 如果您已正确绑定EF模型出价内容,那将不是问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM