Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I don't know what this error means. I am using Visual Studio for Mac 7.5.0 Community version. I am using lazy loading in Entity Framework with ASP.NET Core.

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 Entity Model:

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; }
}

Here is the entity builder:

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");
});

Here is the entity builder for user table:

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 Code:

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;
}

Mapper Class:

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;
}

Repository file:

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;
}

Screenshot of the error message:

error image

Transcript:

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

like image 958
San Jaisy Avatar asked Aug 23 '18 13:08

San Jaisy


1 Answers

From what i understood you where debugging and this occurred which is produced from the Visual Studio debugger's expression elevator so it may means that the debugger was trying to fetch data from an instance that is of type System.Reflection.MethodBase but such object was not available so it produced that error ,

you can try using the legacy debug engine,might fix it (Tools -> Options -> Debugging -> General -> "Use Managed Compatibility Mode")

like image 58
Wesam Avatar answered Nov 20 '22 22:11

Wesam