简体   繁体   English

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

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

I'm using VB.NET MVC 5 with Identity 2.0 . 我正在将VB.NET MVC 5Identity 2.0一起使用

I've been trying to configure my Startup.Auth to automatically use a single instance of ApplicationDbContext, CustomUserManager and CustomRoleManager per request as detailed in this tutorial . 我一直在尝试将Startup.Auth配置为按请求自动使用ApplicationDbContext,CustomUserManager和CustomRoleManager的单个实例, 如本教程中所述

My code is as follows: (minus garbage) 我的代码如下:(减去垃圾)

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

But recieve these errors no matter what I do 但是无论我做什么都接受这些错误

Overload resolution failed because no accessible 'Create' accepts this number of arguments. 重载解析失败,因为没有可访问的“创建”接受此数量的参数。

I think it's to do with me writing in VB and the example being in C#, though it infuriates me that this is a problem. 我认为这与我用VB编写代码以及使用C#编写示例有关,尽管这使我感到恼火,但这是一个问题。 My CustomUserManager is a Public Class, and the Create method is Public Shared. 我的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

Any ideas anyone? 有任何想法吗? Any help is much appreciated, Cheers. 非常感谢您的帮助,干杯。

Try this 尝试这个

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

The AddressOf operator creates a function delegate that points to the function specified by procedurename AddressOf运算符创建一个指向过程名称指定的函数的函数委托

link1 链接1

link2 LINK2

If you have already updated your visual studio 2013 with Update 3. This comes with all the identity stuff and custom user manager, role manager and many more. 如果您已经使用Update 3更新了Visual Studio 2013,则其中包括所有身份信息,自定义用户管理器,角色管理器等。

Create new project using MVC template and Authentication selected as Individual User Accounts using Visual Studio 2013. Then you will get created all the code same as you have already implemented using the example. 使用MVC模板创建新项目,并使用Visual Studio 2013将“身份验证”选择为“个人用户帐户”。然后,您将创建与该示例已实现的所有代码相同的所有代码。 You can use that classes and implementation in order to fix your issues with your custom user manager. 您可以使用该类和实现来解决自定义用户管理器的问题。

Check the floder App_Start >> IdentityConfig.vb 检查选单App_Start >> IdentityConfig.vb

Only thing I can see in your code, you have used integer as Id rather than string. 我在您的代码中只能看到的是,您使用整数作为Id,而不是字符串。 That won't be a problem if you have correctly bind EF model biding stuff. 如果您已正确绑定EF模型出价内容,那将不是问题。

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

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