I have a MVC 5 Web App that has run without problem for 3 years. Yesterday i changed branch and suddenly i get the error "Could not load file or assembly 'System.Web.Http', Version=4.0.0.0"
. This happens in Entity Framework OnModelCreating (though i'm sure EF isn't the problem).
OnModelCreating:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
var entitymethod = typeof(DbModelBuilder).GetMethod("Entity");
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
{
try
{
var a = assembly.GetTypes();
}
catch(ReflectionTypeLoadException ex)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
foreach (Exception exSub in ex.LoaderExceptions)
{
sb.AppendLine(exSub.Message);
System.IO.FileNotFoundException exFileNotFound = exSub as System.IO.FileNotFoundException;
if (exFileNotFound != null)
{
if (!string.IsNullOrEmpty(exFileNotFound.FusionLog))
{
sb.AppendLine("Fusion Log:");
sb.AppendLine(exFileNotFound.FusionLog);
}
}
sb.AppendLine();
}
string errorMessage = sb.ToString();
}
//find alle de klasser der arver fra Entity
var entitytypes = assembly.GetTypes().Where(x => x.IsSubclassOf(typeof(Entity)));
foreach (var type in entitytypes)
{
if(type.Name != "Field")
//lav et DbSet af hver type
entitymethod.MakeGenericMethod(type).Invoke(modelBuilder, new object[] { });
}
}
note the try catch is for debugging this problem. I can see that the assembly that the foreach loop has gotten to is Microsoft.Practices.Unity.WebApi, so i'm guessing this is the assembly needing System.Web.Http. The thing is though, this Web App is running on about 30 different Web Apps for different customers, and neither the servers nor my colleagues computers has that assembly.
I have tried copying the assemblies from a Web App that works perfectly, but to no effect.