Closed mfitconsultants closed 2 years ago
I have the same error when trying to scaffold my database for the first time.
dotnet-ef dbcontext scaffold "Server=localhost;Database=Trust;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -o Schema
C:\Projects\Trust\Trust.Infrastructure>dotnet-ef dbcontext scaffold "Server=localhost;Database=Trust;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -o Schema
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.TypeLoadException: Could not load type 'Microsoft.EntityFrameworkCore.Internal.ProductInfo' from assembly 'Microsoft.EntityFrameworkCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
at Microsoft.EntityFrameworkCore.Design.OperationExecutor..ctor(Object reportHandler, IDictionary args)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(Type type, Object[] args)
at Microsoft.EntityFrameworkCore.Tools.ReflectionOperationExecutor..ctor(String assembly, String startupAssembly, String projectDir, String dataDirectory, String rootNamespace, String language)
at Microsoft.EntityFrameworkCore.Tools.Commands.ProjectCommandBase.CreateExecutor()
at Microsoft.EntityFrameworkCore.Tools.Commands.DbContextScaffoldCommand.Execute()
at Microsoft.EntityFrameworkCore.Tools.Commands.CommandBase.<>c__DisplayClass0_0.<Configure>b__0()
at Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.Execute(String[] args)
at Microsoft.EntityFrameworkCore.Tools.Program.Main(String[] args)
Exception has been thrown by the target of an invocation.
The version of Microsoft.EntityFrameworkCore.Design needs to match Microsoft.EntityFrameworkCore and (I presume) the CLI.
Looks like that might already be the case for @mfitconsultants but perhaps it's worth doing a dotnet restore
just in case the installed packages don't match that csproj file.
Once I had all versions matching, this error message went away for me. E.g.:
dotnet tool install --global dotnet-ef --version 3.0.0-preview9.19423.6
dotnet add package Microsoft.EntityFrameworkCore --version 3.0.0-preview9.19423.6
dotnet add package Microsoft.EntityFrameworkCore.Design --version 3.0.0-preview9.19423.6
when trying to run the
add-migration
command in the PMC is throwing the following error;The command I am running is;
add-migration new-migration -o Data/Migrations
To add, I have the ef code in a seperate class library, below is the
.csproj
for info;I run the migrations through a context factory as follows;
This was working fine up until I upgraded from 2.2.6.