[asp.net-mvc] Attempt by security transparent method 'WebMatrix.WebData.PreApplicationStartCode.Start()'

I've been struggling with a similar issue when upgrading mvc 4 to mvc 5:

Attempt by security transparent method 'System.Web.WebPages.Administration.SiteAdmin.RegisterAdminModule()' to access security critical method 'System.Web.WebPages.ApplicationPart..ctor(System.Reflection.Assembly, System.String)' failed.

The delete extra files check box in the publish dialog solved it for me.