安装 EF Core 3.1.3 后出现此错误 Could not load file or assembly "System Threading Tasks Extensions"

I get this error Could not load file or assembly "System Threading Tasks Extensions" after installing EF Core 3.1.3

我想在我的项目中使用 EF Core,所以我下载了最新的稳定版本 3.1.3
我在包管理器控制台中使用 Scaffold-DbContext 命令从我的数据库创建了一个 DbContext 和 类,在所有事情都建立之后我尝试使用这个代码

 using (var dbContext = new SIMContext())
        {
            var department = new Department();
            department.NameDepartment = txtDepartment.Text;
            department.DescriptionDepartment = txtDescription.Text;

            await dbContext.AddAsync(department).ConfigureAwait(true);
            await dbContext.SaveChangesAsync().ConfigureAwait(true);

        }

但是当我尝试将数据保存到数据库时,在这行代码中

await dbContext.AddAsync(department).ConfigureAwait(true);

我收到这个错误

System.IO.FileLoadException
  HResult=0x80131040
  Message=Impossible de charger le fichier ou l'assembly 'System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' ou une de ses dépendances. La définition trouvée du manifeste de l'assembly ne correspond pas à la référence de l'assembly. (Exception de HRESULT : 0x80131040)
  Source=Smart Industrial Management
  StackTrace:
   at Smart_Industrial_Management.PL.Frm_Department.<btnSave_Click>d__7.MoveNext() in C:\Users\MBoua\source\repos\SIM Windows7 - EF Core5\Smart Industrial Management\PL\Frm_Department.cs:line 107
   at System.Runtime.CompilerServices.AsyncVoidMethodBuilder.Start[TStateMachine](TStateMachine& stateMachine)
   at Smart_Industrial_Management.PL.Frm_Department.btnSave_Click(Object sender, EventArgs e)
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at DevExpress.XtraEditors.BaseButton.OnMouseUp(MouseEventArgs e)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at DevExpress.Utils.Controls.ControlBase.WndProc(Message& m)
   at DevExpress.XtraEditors.BaseControl.WndProc(Message& msg)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
   at Smart_Industrial_Management.PL.FrmLogin.<btnLogin_Click>d__7.MoveNext() in C:\Users\MBoua\source\repos\SIM Windows7 - EF Core5\Smart Industrial Management\PL\FrmLogin.cs:line 108

我尝试清理我的解决方案并清除 NuGet 缓存,但我仍然遇到同样的错误。
我在 .NET Core 5 和 EF Core 5 上尝试了相同的代码,我成功了。
我的项目在:
.NET 框架 4.7.2
EF 核心 3.1.3
系统线程任务扩展 4.5.4

我该如何解决这个问题?

它正在寻找 System.Threading.Tasks.Extensions 的早期版本,版本=4.2.0.0。

您可以尝试程序集版本重定向:https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/redirect-assembly-versions

如果您在程序集的主要版本之间重定向,这当然会产生问题。

希望对您有所帮助