我正在使用 VB.NET MVC 5 和 Identity 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 指定的函数
关于asp.net-mvc - VB.NET MVC 重载解析失败,因为没有可访问的 'Create' 接受此数量的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26178674/