1

I have a C# / ASP.NET MVC project using Entity Framework 6. When I am deploying database migrations by running

Update-Database -Verbose

in the Package Manager Console in Visual Studio, everything works.

With the -Verbose flag, this is the (slightly redacted) command that is displayed in the console and that I assume is what is actually executed:

{package dir}\EntityFramework.6.5.1\tools\net45\any\ef6.exe 
    database update --verbose --no-color --prefix-output --assembly {assembly dll}
    --project-dir {project dir} --language C# --data-dir {data dir} 
    --root-namespace <namespace> --config {config dir/Web.config}

When I run that exact same command (via copy/paste) in a PowerShell console (i.e., NOT within the Package Manager Console in Visual Studio), I get assembly binding redirect errors.

info: System.IO.FileLoadException: Could not load file or assembly 'System.ComponentModel.Annotations, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

In my config files, I have these assembly binding redirects:

<dependentAssembly>
    <assemblyIdentity name="System.ComponentModel.Annotations" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.2.1.0" />
</dependentAssembly>

It seems like ef6.exe is not respecting my assembly binding redirects when run outside the Package Manager Console.

Do you have any ideas on why the same ef6.exe command fails to load the assembly when run from a PowerShell console, but works fine in the Package Manager Console in Visual Studio? What context is established in the Package Manager Console that doesn't exist in a PowerShell console?

2
  • It seems that the System.ComponentModel.Annotations assembly isn't available in a regular Windows PowerShell session (built on .NET Framework), but it is in a PowerShell (Core) 7 session (built on .NET (Core)). Commented Apr 5 at 17:04
  • I would have expected ef6.exe to use normal dll resolution patterns, which would involve looking in the application directory first. System.ComponentModel.Annotations.dll (v4.2.1.0) is in the bin directory alongside all the other project dlls. The issue is just that it is looking for the wrong version. Commented Apr 7 at 13:01

0

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.