Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
3.87/5 (4 votes)
I am carefully going through the book: "Pro ASP.NET MVC 4" (By Adam Freeman) and was able to make it to page 182 before encountering the following error in a runtime window labeled:

"FileLoadException was unhandled by user code".

The message in its entirety reads:

"An exception of type 'System.IO.FileLoadException' occurred in Ninject.dll but was not handled in user code

Additional information: Could not load file or assembly 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)".

(to me this is suggesting I change the manifest definition but I do not know how)

When I use MOQ, instead of Entity framework I do not get the error message and my code works fine.

C#
// this code block works
Mock<IProductRepository> mock = new Mock<IProductRepository>();
mock.Setup(m => m.Products).Returns(new List<Product>{
    new Product {Name = "Football", Price = 25},
    new Product {Name = "Surf board", Price = 179},
    new Product {Name = "Running shoes", Price = 95}
}.AsQueryable());
ninjectKernel.Bind<IProductRepository>().ToConstant(mock.Object);


But when I replace the above 7 lines of working code with the following single line of code, as the book instructs me to:

C#
ninjectKernel.Bind<IProductRepository>().To<EFProductRepository>();


the error message comes back to haunt me. It is clear to me that the problem surely has something to do with the Entity Framework being used to read from the database. (Note the database is populated and is in the open mode when I run the EF code).

If anyone can give me complete and clear instructions on how to resolve this mismatch I would appreciate it. The error message points out the problem but seems to ASSUME I know just what dll or assembly to 'tamper' with and just what changes to make, where to go to make these changes, how to get to the manifest. I would really appreciate a set of instructions on how to go about this (and guard with my life forever more :)).

To any/all who can help, thank you VERY much in advance

Paul
Posted
Updated 3-Jan-14 9:24am
v7
Comments
db7uk 3-Jan-14 15:39pm    
Hiya, I had a similar issue. Are you sure that all projects in your solution that have a dependency on EF have the right assembly version? Also are you using a boostrapper on assmebly start to add the references to the container?

My issue was that EF did not play nicely with the EFContext. The other issue was that if you use a ef repository then controlling when the connection opens and closes really helped me.

What is the EFProductRepository code and the EFDataContext code?
pes1957 3-Jan-14 16:35pm    
db7uk - I would gladly send you the whole project, thus far, so you can see just what is happening. Anyway, the Codes you are asking for follow:

THE REPOSITORY
using SportsStore.Domain.Abstract;
using SportsStore.Domain.Entities;
using System.Linq;

namespace SportsStore.Domain.Concrete
{
public class EFProductRepository : IProductRepository
{
private EFDbContext context = new EFDbContext();

public IQueryable<Product> Products
{
get { return context.Products; }
}
}
}


THE DATA CONTEXT
using SportsStore.Domain.Entities;
using System.Data.Entity;

namespace SportsStore.Domain.Concrete
{
public class EFDbContext : DbContext
{
public DbSet<Product> Products { get; set; }
}
}

Let me know how you feel about really taking this down to the ATOM.

TY

Paul


Member 13004121 16-Feb-17 21:38pm    
g
db7uk 5-Jan-14 15:12pm    
Hi thanks for the reply. I am sorry but I cannot determine the issue from the code. I would be more than happy to take a peek at the project and give any feedback. I may not be able to fix it but as they say, two heads are better than one! If you do let me know.
pes1957 6-Jan-14 0:31am    
Yes, it seems visual studio is acting very strange all of a sudden. I bought and installed a program called PC Helper 360 and, I am not quite sure, but since around then (the next day) when I went to load VS 2013 it took forEVER to launch and the same with REBUILD and running it. I do not know what happened, but when I would run a build/rebuild in the past it would build my 3 projects each once, as in 123. Now it builds 1,twice, 2 three times, and 3, twice. See the new info on builds it has been giving me below (notice the added complaint in build 2 of 2 about a versoion mismatch:

1>------ Rebuild All started: Project: SportsStore.Domain, Configuration: Debug Any CPU ------
1> SportsStore.Domain -> C:\Projects\SportsStore\SportsStore.Domain\bin\Debug\SportsStore.Domain.dll
2>------ Rebuild All started: Project: SportsStore.WebUI, Configuration: Debug Any CPU ------
2>C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(1635,5): warning MSB3277: Found conflicts between different versions of the same dependent assembly that could not be resolved. These reference conflicts are listed in the build log when log verbosity is set to detailed.
2> SportsStore.WebUI -> C:\Projects\SportsStore\SportsStore.WebUI\bin\SportsStore.WebUI.dll
3>------ Rebuild All started: Project: SportsStore.UnitTests, Configuration: Debug Any CPU ------
3> SportsStore.UnitTests -> C:\Projects\SportsStore\SportsStore.UnitTests\bin\Debug\SportsStore.UnitTests.dll
========== Rebuild All: 3 succeeded, 0 failed, 0 skipped ==========


This is puzzling to me as well as discouraging. I searched all over to find out why it takes over 5 minutes JUST to get VS up and running. I even did a repair on it - and still it is slow on everything it does,,,, even when I click on a button to open file or view it hangs a tad bit.

If you have ever encountered this and resolved it I would be indebted. My only other choice would be to wipe my hard drive and reload from scratch, something I do NOT want to to.

Paul




1 solution

After reviewing the code pes1957 sent to me I was able to determine that there was indeed an assembly reference error.

Basically the number of projects that were in the solution had a mixture of version 5 and 6 Entity Framework references. I updated the references, and web.config to show the correct version number and all compiles correctly.
 
Share this answer
 
v2
Comments
Sachin Limbu 10-Aug-15 6:58am    
Sorry if possible you could paste the runtime Code, would much appreciate....it

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900