asp.net-mvc - VB.NET MVC 重载解析失败,因为没有可访问的 'Create' 接受此数量的参数

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

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

我一直在尝试将 Startup.Auth 配置为根据请求自动使用 ApplicationDbContext、CustomUserManager 和 CustomRoleManager 的单个实例 as detailed in this tutorial .

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

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

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

Overload resolution failed because no accessible 'Create' accepts this number of arguments.

我认为这与我用 VB 编写而示例是用 C# 相关,尽管这让我很生气,因为这是一个问题。我的CustomUserManager是一个Public Class,Create方法是Public Shared。

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 运算符创建一个函数委托(delegate),该委托(delegate)指向由 procedurename 指定的函数

link1

link2

关于asp.net-mvc - VB.NET MVC 重载解析失败,因为没有可访问的 'Create' 接受此数量的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26178674/

相关文章:

c# - 在 C# 或 VB.NET 中寻找开源或低成本开发许可证调查/表单生成器应用程序

c# - Razor 页面中 VB.NET 的 @@<text> 标签问题

javascript - 如果我将 Div 设置为 runat ="server",则不显示 Jqwidgets 图表

command - 如何在启动时运行命令?

macos - com.install4j.runtime.launcher启动时使可执行文件崩溃-Mac

asp.net-mvc - 使用引用 URL 和语言选择重建 Razor URL

asp.net-mvc - MVC actionlink posting 复杂类型列表

javascript - @Html.Editor() 的onfocus 和onblur 事件怎么写?

c# - 深入理解MVC .net中的延迟加载和处理错误

java - 在 Windows 上使用startup.bat 运行 Tomcat8 时的 JVM 选项