Running update-database
from the Package Manager Console on an ASP.NET MVC Web Application fails after I add an unrelated Wix setup project to my solution.
Why is update-database
accessing this unrelated project? Why does the presence of the wix project trigger a load of an assembly that cannot be found? How do I fix this?
This happens in a larger solution with web, desktop, installer projects, but after considerable head-scratching I reproduced this in isolation:
WebMatrix.WebData.WebSecurity.InitializeDatabaseConnection(..)
and System.Web.Security.Roles
.Run update-database
. It will work fine. Now add a Wix setup project (no need to configure) and it will fail at/before executing Seed()
with
Could not load file or assembly 'Microsoft.Build.Framework, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
So, it seems having a Wix project in my solution triggers the load of an additional (not found) assembly when trying to call WebSecurity / WebMatrix methods through update-database from the Package Manager Console.
Workaround: Unload the Wix setup project and restart Visual Studio. There is no need to remove the project entirely.
Adding the missing dll to the GAC or a reference to the machine.config does not help. The dll is found but loading it errors out with
System.IO.FileLoadException: Loading this assembly would produce a different grant set from other instances. (Exception from HRESULT: 0x80131401)
Using FUSLOGVW.exe
to log assembly load events didn't help. It basically shows that update-database
can't find the v15.1 dll because it's not in the GAC and there is no app/host/system config file pointing at it.
Running the seed method from the running web application (enable automatic migration) works fine.
And yes, I am setting PMC "default project" to the web application, ie, point update-database
at the web application.
Details:
Snippets:
Configuration.cs:
class Configuration : DbMigrationsConfiguration<MyDbContextHere>
{
public Configuration() { AutomaticMigrationsEnabled = false; }
protected override void Seed(Stash context)
{
WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfiles", "UserId", "UserName", autoCreateTables: true);
if(!Roles.RoleExists("G1")) Roles.CreateRole("G1");
}
}
`
web.config:
`
<configuration>
<system.web>
<roleManager enabled="true" defaultProvider="SimpleRoleProvider">
<providers>
<clear />
<add name="SimpleRoleProvider" type="WebMatrix.WebData.SimpleRoleProvider, WebMatrix.WebData" />
</providers>
</roleManager>
User contributions licensed under CC BY-SA 3.0