'scaffold-DbContext , command results in exception: System.Reflection.TargetInvocationException

When attempted to run a scaffold command I am now receieving the exception noted below. It may be important to note that this stopped working all of a sudden.

Command executed

Scaffold-DbContext "Server=tcp:<CONNECTION STRING REMOVED FOR STACK OVERFLOW POST>;Initial Catalog=DATABASENAME;Persist Security Info=False;User ID=DBUSER;Password=PASSWORD;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir EntityModel -Force -Context "THECONTEXT"

Resulting Exception thrown:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.TypeLoadException: Could not load type 'Microsoft.EntityFrameworkCore.Internal.SemanticVersionComparer' from assembly 'Microsoft.EntityFrameworkCore, Version=5.0.16.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'

Installed EF CORE Packages installed packages ef core 5



Solution 1:[1]

The issue relate the Microsoft.EntityFrameworkCore package version, try to update/install/re-install the Microsoft.EntityFrameworkCore 5.0 package.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Zhi Lv