簡體   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