"Inspecting the state of an object in the debuggee of type System.Reflection.MethodBase is not supported in this context"
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")
Related videos on Youtube
![San Jaisy](https://i.stack.imgur.com/YSzYR.jpg?s=256&g=1)
San Jaisy
Updated on June 13, 2022Comments
-
San Jaisy about 2 years
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:
Transcript:
Inspecting the state of an object in the debuggee of type System.Reflection.MethodBase is not supported in this context.
-
Nkosi almost 6 yearsIs this error stopping the code from executing?
-
San Jaisy almost 6 yearsyes. Code doesn't execute after that..
-
Steve Py almost 6 yearsPlease add the code for
_adminGenericRepository.FindAsync()
, as well as the whole code line from the breakpoint in the image:var user = await ....
When left to run without the breakpoint, what exception is raised? -
San Jaisy almost 6 yearsadd full code. Getting error on SelectedRole = mapRoleDbDataToViewModel(user.RoleAssign != null ? user.RoleAssign.FirstOrDefault().Role : null) . Due to that error
-
San Jaisy almost 6 years@StevePy - I found that --> Lazy Loading doesn't fit well with the Async pattern. Can you have any idea related to this issue
-
-
Steve Py almost 6 yearsHow do you mean the "right way"? About the treatment of the password or populating the view model? Does it not work?
-
San Jaisy almost 6 yearspopulating the view model. I haven't tried ... Since lots of code with this approach
-
Steve Py almost 6 yearsThe extra step to populate a view model (vs. doing it in the EF
.Select()
expression is only if you need to call a C# function (mapRoleDbDataToViewModel
). EF would attempt to pass that function to SQL Server which will have no knowledge of that function. Instead, if you can create the view model from the related data (user.RoleAssign.Role
) then you can populate the complete view model structure in one expression. Try it first, figure out how to make it work, then optimize it from there. -
San Jaisy almost 6 yearsI am using visual studio for mac. I don't find that option as you said. I tried to find that option but haven't found.
-
Wesam almost 6 yearsthis msdn blog was my reference blogs.msdn.microsoft.com/devops/2013/10/16/… , its for vs2013 and works also for VS2015 , go through it maybe you missed a step
-
Wesam almost 6 yearsthere is another way actually ,right click and select Properties of your project , go to "Debug" then select the check box "Enable native code debugging" i think this is available in vs for mac
-
Wesam almost 5 years@ZulqarnainJalil , are you still getting the same exception or did it change ? after you did the above
-
Kolichikov over 4 yearsUse Manager Compatibility Mode resolved this issue for me on VS2019/Win 10.
-
JHBonarius over 2 years@Kolichikov I didn't get this at first, but now I realized Microsoft removed this in VS2022!!!. that sux.