I have an ASP.NET Core 6.0 MVC web app project, and my Entity Framework Core 7.0.9, and Identity 6.0.2.
Before I add my database to the project all the page is worked find and show in browser. but after I add my database I got the this error when I want open my page:
An unhandled exception occurred while processing the request. MissingMethodException: Method not found: 'Boolean Microsoft.AspNetCore.Cryptography.UnsafeNativeMethods.CryptProtectData(Microsoft.AspNetCore.Cryptography.DATA_BLOB*, IntPtr, Microsoft.AspNetCore.Cryptography.DATA_BLOB*, IntPtr, IntPtr, UInt32, Microsoft.AspNetCore.Cryptography.DATA_BLOB ByRef)'.
Microsoft.AspNetCore.DataProtection.Cng.DpapiSecretSerializerHelper.ProtectWithDpapiCore(Byte* pbSecret, uint cbSecret, Byte* pbOptionalEntropy, uint cbOptionalEntropy, bool fLocalMachine) CryptographicException: An error occurred while trying to encrypt the provided data. Refer to the inner exception for more information. For more information go to http://aka.ms/dataprotectionwarning
Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.Protect(byte[] plaintext)
This error is shown even for the page and their controller not attach to database yet.
Also I only programming role table now and this is the controller:
public class ManageRoleController : Controller
{
private readonly RoleManager<IdentityRole> _roleManager;
public ManageRoleController(RoleManager<IdentityRole> roleManager)
{
_roleManager = roleManager;
}
public IActionResult Index()
{
var roles = _roleManager.Roles.ToList();
return View("Role", roles);
}
}
but when I want open this page the page is completely white and not show anything.
How can fix these two problems?
This is my html for role page :
<div class=" mt-5 mx-2" id="mainContent">
<div class="row text-end mt-0 mb-5 border-0 border-bottom border-bottom-2 border-dark ">
<div class="col-12 mb-2 "><b>مدیریت نقشها</b></div>
<div class="col-12">
<table class="table table-light table-striped border border-1 table-hover text-center w-100" id="ReoprtTable">
<thead>
<tr>
<th style="width:90px;">ردیف </th>
<th >نقش</th>
<th >عملیات </th>
</tr>
</thead>
<tbody>
@{
if (!Model.Any())
{
<tr>
<td colspan="3">هنوز هیچ مقامی تعریف نشده است</td>
</tr>
}
else
{
for (int i = 1; i < Model.Count + 1; i++)
{
<tr>
<td style="display:none;">@Model[i - 1].Id</td>
<td>@i</td>
<td>@Model[i - 1].Name</td>
<td>
<a data-toggle="modal" href="#exampleModal" class="btn btn-warning testeditbtn w-50 float-right Update_Button">بروزرسانی</a>
<button type="button" class="btn btn-danger float-left w-50 Delete_Button ">حذف</button>
</td>
</tr>
}
}
}
</tbody>
</table>
<div class="col-12 my-2">
<form asp-action="Search" asp-controller="User" class="d-flex w-50 " method="post">
<input class="form-control border-info " type="search" placeholder="نقش جدید" aria-label="نقش جدید" name="search">
<button class="btn btn-outline-info bg-info text-light me-2" type="submit">افزودن</button>
</form>
</div>
</div>
</div>
</div>
And this is the DB class: (I am not copy the dbset)
public class DB : IdentityDbContext<User>
{
public DB() : base() { }
public DB(DbContextOptions<DB> options) : base(options)
{
}
protected override void OnConfiguring(DbContextOptionsBuilder OptionsBuilder)
{
OptionsBuilder.UseSqlServer(@"data source=.;initial catalog = stor; integrated security = true;TrustServerCertificate=True;");
base.OnConfiguring(OptionsBuilder);
}
}
Please help.
The error message is indicating a nuget package incompatible issue.
However, Microsoft.EntityFrameworkCore --version 7.0.9
is allowed to work with Microsoft.AspNetCore.Identity.EntityFrameworkCore --version 6.0.0
in a .net 6 application. See this official document.
EF7 targets .NET 6, and so can be used with either .NET 6 (LTS) or .NET 7.
OP also kindly proved that there's another nuget package which is incompatible with identity version and .net 6. Upgrading all of them to last version and using the .NET 7 instead could solve the issue.