3
votes

Fellow developers,

I've encountered a problem in my dev environment. I've created a project which uses EntityFramework and ASP.NET Identity, and then a few other projects like WCF service and WebForms site that reference the first one. The projects compile and work fine, but when I try to use "Update-Database" in Package Manager Console to update my migration-enabled database i get:

System.Data.Entity.Core.MetadataException: Schema specified is not valid. Errors: (0,0) : error 0004: Could not load file or assembly 'Microsoft.AspNet.Identity.EntityFramework, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

The version of Microsoft.AspNet.Identity.EntityFramework I'm referencing in every project is 2.0.0.0 (I upgraded it at some point with NuGet). How to find out who is looking for the old version and fix that problem?

I've tried the following steps:

  • Manually checked the references for every project in Visual Studio. All of them had correct version (2.0.0.0) and DLL path specified and "Specific version" property set to "False".

  • Cleared the "Temporary ASP.NET Files" in my AppData and C:\Windows...

  • Of course cleared the entire solution (deleted bin & obj folders)

  • Manually checked every *.csproj file for invalid references

  • Reinstalled the packages with NuGet (Update-Package -includePrerelease -reinstall)

  • Included assembly binding redirection in every App.config/Web.config:

<runtime>
  <assemblyBinding>
    <dependentAssembly>
      <assemblyIdentity name="Microsoft.AspNet.Identity.EntityFramework" publicKeyToken="31bf3856ad364e35" culture="neutral" />
      <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
    </dependentAssembly>
  </assemblyBinding>
</runtime>
  • Got the Fusion Log:
*** Assembly Binder Log Entry  (2014-04-18 @ 01:10:23) ***

The operation failed.
Bind result: hr = 0x80131040. No description available.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: DisplayName = Microsoft.AspNet.Identity.EntityFramework, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
 (Fully-specified)
LOG: Appbase = file:///C:/Developer/sharp/projects/ShadowServer/DataModel/bin/Debug/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = NULL
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Developer\sharp\projects\ShadowServer\DataModel\tmp2BEF.tmp
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Microsoft.AspNet.Identity.EntityFramework, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/Developer/sharp/projects/ShadowServer/DataModel/bin/Debug/Microsoft.AspNet.Identity.EntityFramework.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\Developer\sharp\projects\ShadowServer\DataModel\bin\Debug\Microsoft.AspNet.Identity.EntityFramework.dll
LOG: Entering download cache setup phase.
LOG: Assembly Name is: Microsoft.AspNet.Identity.EntityFramework, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: The assembly reference did not match the assembly definition found.
ERR: Setup failed with hr = 0x80131040.
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

Sorry for my English in advance :)

1
Use the debugger. Debug + Exceptions, tick the Thrown checkbox for CLR exception to get it to stop on the failed load. The Stack Trace window shows you who's guilty.Hans Passant
But the exception is thrown in Visual Studio's built-in Package Manager Console. To be specific when using "Update-Database" cmdlet, so are you sure I can use the debugger for that? My apps (the website and web service) don't have any runtime problems nor throw exceptions at any time.Michael K. Sondej
Yes, start another instance of VS. Tools + Attach to Process to have it debug the first one.Hans Passant

1 Answers

0
votes

In my case I was getting this below error:

Could not load file or assembly 'Microsoft.AspNet.Identity.EntityFramework, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference.

I realized that my main UI startup project had old versions of Microsoft.AspNet.Identity.EntityFramework by default... (whereas in the other datalayer project I had manually gotten the latest libraries) so just updated the main project also from NUGet.