VB.NET MVC重载解析失败,因为无法访问'创建'接受这个数量的论点

时间:2014-10-03 12:10:01

标签: asp.net-mvc vb.net startup asp.net-identity owin

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

我一直在尝试将Startup.Auth配置为根据请求as detailed in this tutorial自动使用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

但无论我做什么都会收到这些错误

  

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

我认为这与我在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

任何想法?任何帮助都非常感谢,干杯。

2 个答案:

答案 0 :(得分:3)

试试这个

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

AddressOf运算符创建一个函数委托,指向procedurename

指定的函数

link1

link2

答案 1 :(得分:0)

如果您已使用Update 3更新了visual studio 2013.这包含所有身份资料和自定义用户管理器,角色管理器等等。

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

检查floder App_Start>> IdentityConfig.vb

我只能在你的代码中看到,你使用整数作为Id而不是字符串。如果你正确绑定EF模型的东西,这将不会是一个问题。