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

0

I'm trying to use EF Core in my project so I download the last stable version 3.1.3
I created a DbContext and classes from my database using Scaffold-DbContext command in Package Manager console, and after all thing are establish I try to using this code

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

        }

but when I try to save data to the database and in this line of code

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

I get this error

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

I try to clean my solution and clear NuGet caches but I still have the same error.
I try the same code with .NET Core 5 and EF Core 5 and I succeeded.
My project is on:
.NET framework 4.7.2
EF Core 3.1.3
System Threading Tasks Extensions 4.5.4

How can I solve this problem?.

c#
winforms
devexpress
ef-core-3.1
asked on Stack Overflow Apr 6, 2020 by M.Bouabdallah • edited Apr 7, 2020 by Miamy

1 Answer

1

It is looking for an earlier version of System.Threading.Tasks.Extensions, Version=4.2.0.0.

You can try Assembly version redirection: https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/redirect-assembly-versions

This can of course produce problems if you are redirecting between major versions of an assembly.

Hope this helps

answered on Stack Overflow Apr 7, 2020 by Oguz Ozgul

User contributions licensed under CC BY-SA 3.0