I have setup a database using Entity Framework, code first, every time I try to add a migration or update the database I get the following error message:
PM> update-database Exception calling "CreateInstance" with "7" argument(s): "Constructor on type 'System.Data.Entity.Migrations.Utilities.DomainDispatcher' not found." At D:\WTS Projects\ModelCalibration\packages\EntityFramework.6.2.0\tools\EntityFramework.psm1:783 char:5 + $dispatcher = $utilityAssembly.CreateInstance( + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) , MethodInvocationException + FullyQualifiedErrorId : MissingMethodException System.NullReferenceException: Object reference not set to an instance of an object. at System.Data.Entity.Migrations.MigrationsDomainCommand.WriteLine(String message) at System.Data.Entity.Migrations.UpdateDatabaseCommand.<>c__DisplayClass2.<.ctor>b__0() at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command) Object reference not set to an instance of an object.
I have copied the project to another computer with the same version of Visual Studio, Entity Framework & Windows and I am able to migrate the database with no issues at all. I have also downloaded the sample project on these docs on both machines, and got the same exception on this machine but the other one again had no issues, so I believe its nothing to do with my code.
The only solution I have been able to find is on this thread here, where the solution was to reinstall windows which I am not so keen to do.
I have also tried everything said in other similar SO posts, such as Exception raised when I'm trying enable migrations in EF 4.3.1 , which was to, reinstall Entity Framework, repair Visual Studio, etc...
I am using Enitiy Framework v6.2.0, Visual Studio v15.8.4, .NET Framework 4.6.1 and Windows 10.
Has anyone seen this issue before and/or know any possible solutions?
Okay I found a solution that works, thanks to @rho24 on this thread! I will also repost the solution here for anyone that has the issue:
The problem is that on my machine is that version 188.8.131.52 of the System.Management.Automation assembly is loaded in the package management console, and EntityFramework.PowerShell.Utility.dll is build against version 184.108.40.206.
I have a temporary fix of adding the following binding redirect to
<dependentAssembly> <assemblyIdentity name="System.Management.Automation" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="0.0.0.0-220.127.116.11" newVersion="18.104.22.168"/> <publisherPolicy apply="no" /> </dependentAssembly>
Note, the fix needs to be applied everytime you update VS.
I was able to figure this out as its the same issue as this one
Which i was also having, but was fixed in a recent VS update. Hopefully the fix they applied is easy for you too!
Again credit to @rho24 for the solution! :D
It sometimes work to just clean and rebuild your solution