c# - The non-generic method cannot be used with type arguments in this context 是什么意思?

标签 c#

我有以下类和方法:

public class UserManager<TUser, TKey> : IDisposable
    where TUser : class, global::Microsoft.AspNet.Identity.IUser<TKey>
    where TKey : global::System.IEquatable<TKey> {

   public virtual Task<TUser> FindByIdAsync(TKey userId);

和:

private ApplicationUserManager _userManager;
    public ApplicationUserManager UserManager
    {
        get
        {
            return _userManager ?? Request.GetOwinContext().GetUserManager<ApplicationUserManager>();
        }
        set
        {
            _userManager = value;
        }
    }

public class ApplicationUserManager : UserManager<ApplicationUser, int>
public class ApplicationUser : IdentityUser<int, CustomUserLogin, CustomUserRole, CustomUserClaim>

我想像这样调用这个方法:

var user = await UserManager.FindByIdAsync<ApplicationUser,int>(99);

它给我错误:

非泛型方法

'Microsoft.AspNet.Identity.UserManager.FindByIdAsync(int)' cannot be used with type arguments

最佳答案

如错误所述,FindByIdAsync不接受类型参数。这些存在于声明类 UserManager<TUser, TKey>

var user = await UserManager.FindByIdAsync(99);

关于c# - The non-generic method cannot be used with type arguments in this context 是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24574013/

相关文章:

c# - 领域驱动设计聚合引用问题

c# - Windows Phone 使 Segoe UI 符号不显示为表情符号

c# - Entity Framework 跟踪更改

c# - C#中的404错误

c# - 在旋转 Windows Phone 期间防止图像剪切

c# - Process.Start 导致我的 WPF 程序崩溃

c# - 如何在 asp.net 中显示多个图像 tiff 文件?

c# - 在变量名开头使用数字

C# 客户端-服务器视频流

C#:为什么 .ToString() 将文本更快地附加到转换为字符串的 int 中?