2

After upgrading from EF 4.2 and Migration to EF 4.3 and enabling migration,restarting Visual studio and everything , whenever I try to call Update-Database/Add-Migration I get this:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException:
The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
--- End of inner exception stack trace ---
at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters)
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
at System.Management.Automation.ComMethod.InvokeMethod(PSMethod method, Object[] arguments)
Update-Database : Exception has been thrown by the target of an invocation.
At line:1 char:1
+ update-database
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (Exception has b... an invocation.:String) [Update-Database], RuntimeException
+ FullyQualifiedErrorId : Exception has been thrown by the target of an invocation.,Update-Database

I tried cleaning the whole project , deleting ef and migration and packages folder and doing it from the beginning and still same error !

Anyone facing the same error? Or have a solution for this?

2 Answers 2

5

In case you have context and migration in separate projects, you need to use -StartupProjectName "YourProject" option of add-migration and update-database

The same error was in 4.3 beta. I encountered it in 4.3 release as well.

Sign up to request clarification or add additional context in comments.

2 Comments

I noticed this too. But a little different in my case. I have my DbContext and Migrations in ONE project. But it is not the startup project. Adding -StartupProjectName solves this too. Really annoying to type this everytime.
Yeah Ef Team confirmed this which i find strange as builds before 4.3 didnt suffer from this !
3

Instead of using the Powershell commands, you can control the migration via code, and then tell it where your assembly and context are:

var configuration = new DbMigrationsConfiguration() {
  MigrationsAssembly = typeof(YourMigrations).Assembly,
  ContextType = typeof(YourContext)
};

Then you can either script it out or auto-run it by using the DbMigrator class:

var migrator = new DbMigrator(configuration);
var scripter = new MigratorScriptingDecorator(migrator);
string script = scripter.ScriptUpdate(null, null);

2 Comments

im very interested in this can you please explain more ?
You might just want to check out the MSDN documentation for DbMigrator

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.