草庐IT

c# - "Inspecting the state of an object in the debuggee of type System.Reflection.MethodBase is not supported in this context"

coder 2024-05-26 原文

我不知道这个错误是什么意思。我使用的是 Visual Studio for Mac 7.5.0 社区版。我在带有 ASP.NET Core 的 Entity Framework 中使用延迟加载。

public partial class AdminUser
{
    public AdminUser()
    {
        RoleAssign = new HashSet<RoleAssign>();
    }

    public Guid UserId { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string Email { get; set; }
    public string UserName { get; set; }
    public byte[] Password { get; set; }
    public DateTime CreatedTimeStamp { get; set; }
    public DateTime? ModifiedTimeStamp { get; set; }
    public DateTime? LogDate { get; set; }
    public short? LogNumber { get; set; }
    public bool ReloadActiveFlag { get; set; }
    public bool IsActive { get; set; }
    public string ExtraText { get; set; }
    public string ResetPasswordToken { get; set; }
    public DateTime? ResetPasswordTokenCreatedTimeStamp { get; set; }

    public virtual ICollection<RoleAssign> RoleAssign { get; set; }
}

RoleAssign 实体模型:

public partial class RoleAssign
{
    public Guid RoleAssignId { get; set; }
    public Guid RoleId { get; set; }
    public Guid UserId { get; set; }

    public virtual AdminRole Role { get; set; }
    public virtual AdminUser User { get; set; }
}

这是实体构建器:

modelBuilder.Entity<RoleAssign>(entity =>
{
    entity.Property(e => e.RoleAssignId).ValueGeneratedNever();

    entity.HasOne(d => d.Role)
        .WithMany(p => p.RoleAssign)
        .HasForeignKey(d => d.RoleId)
        .OnDelete(DeleteBehavior.ClientSetNull)
        .HasConstraintName("FK__RoleAssig__RoleI__160F4887");

    entity.HasOne(d => d.User)
        .WithMany(p => p.RoleAssign)
        .HasForeignKey(d => d.UserId)
        .OnDelete(DeleteBehavior.ClientSetNull)
        .HasConstraintName("FK__RoleAssig__UserI__17036CC0");
});

这是用户表的实体构建器:

modelBuilder.Entity<AdminUser>(entity =>
{
    entity.HasKey(e => e.UserId);

    entity.Property(e => e.UserId).ValueGeneratedNever();

    entity.Property(e => e.CreatedTimeStamp)
        .HasColumnType("datetime")
        .HasDefaultValueSql("(getdate())");

    entity.Property(e => e.Email)
        .IsRequired()
        .IsUnicode(false);

    entity.Property(e => e.ExtraText).IsUnicode(false);

    entity.Property(e => e.FirstName)
        .IsRequired()
        .IsUnicode(false);

    entity.Property(e => e.IsActive)
        .IsRequired()
        .HasColumnName("isActive")
        .HasDefaultValueSql("((1))");

    entity.Property(e => e.LastName)
        .IsRequired()
        .IsUnicode(false);

    entity.Property(e => e.LogDate).HasColumnType("datetime");

    entity.Property(e => e.ModifiedTimeStamp).HasColumnType("datetime");

    entity.Property(e => e.Password).IsRequired();

    entity.Property(e => e.ResetPasswordToken).IsUnicode(false);

    entity.Property(e => e.ResetPasswordTokenCreatedTimeStamp).HasColumnType("datetime");

    entity.Property(e => e.UserName)
        .IsRequired()
        .IsUnicode(false);
});

UOW 代码:

public async Task<UserViewModel> AdminAuthentication(UserViewModel userView)
{
    var user = await _adminGenericRepository.FindAsync(x => x.IsActive && x.UserName.Equals(userView.UserName) && (AesEncryptAndDecrypt.DecryptStringFromBytes(x.Password, crytograpyKey, crytograpyIV).Equals(userView.Password)));

    if (user != null)
    {
        return new UserViewModel
        {
            UserId = user.UserId,
            isActive = user.IsActive,
            UserName = user.UserName,
            LastName = user.LastName,
            FirstName = user.FirstName,
            SelectedRole = mapRoleDbDataToViewModel(user.RoleAssign != null ? user.RoleAssign.FirstOrDefault().Role : null)
        };
    }
    return null;
}

映射器类:

private RoleViewModel mapRoleDbDataToViewModel(AdminRole dbRole)
{
    if (dbRole != null)
    {
        return new RoleViewModel
        {
            RoleId = dbRole.RoleId,
            RoleName = dbRole.RoleName,
            RoleType = dbRole.RoleType,
            SortOrder = dbRole.SortOrder,
            TreeLevel = dbRole.TreeLevel,
            Permissions = GetRuleByRoleId(dbRole.RoleId)
        };
    }
    return null;
}

存储库文件:

public virtual async Task<T> FindAsync(Expression<Func<T, bool>> predicate)
{
    return await _entities.Set<T>().SingleOrDefaultAsync(predicate);
}

public IQueryable<T> FindBy(System.Linq.Expressions.Expression<Func<T, bool>> predicate)
{
    IQueryable<T> query = _entities.Set<T>().Where(predicate);
    return query;
}

错误信息截图:

成绩单:

Inspecting the state of an object in the debuggee of type System.Reflection.MethodBase is not supported in this context.

最佳答案

根据我对你的理解,调试发生在 Visual Studio 调试器的表达式电梯中,因此这可能意味着调试器试图从 System.Reflection.MethodBase 类型的实例中获取数据,但此类对象不可用,所以它产生了那个错误,

您可以尝试使用旧版调试引擎,可能会修复它 (工具 -> 选项 -> 调试 -> 常规 -> “使用托管兼容模式”)

关于c# - "Inspecting the state of an object in the debuggee of type System.Reflection.MethodBase is not supported in this context",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51987315/

有关c# - "Inspecting the state of an object in the debuggee of type System.Reflection.MethodBase is not supported in this context"的更多相关文章

随机推荐