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.
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:
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