10

The question is how to resolve conflicts between versions of assemblies in my project that was upgraded to MVC4 and EF5?

The problem is manifest in the fact that my controllers and models can include System.Data.Objects, but now my views.

I am using MVC 4, my project was upgraded from MVC 3.

Entity Framework is version 5.

I have a controller that is able to use objectcontext from System.Data.Objects.

My Usings: using System.Data.Objects; using System.Data.Entity;

When I try to include the using in the view form System.Data.Objects, I get :

CS0234: The type or namespace name 'Objects' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)

I am targeting .net 4.5

My Build Displays this message: C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1561,5): warning MSB3247: Found conflicts between different versions of the same dependent assembly.

4
  • 1
    I'm not entirely sure what your problem is but I guess my first question would be is there anyway you can avoid interacting with the objectcontext from the view? This is generally a bad idea and violates the rules of your view being "dumb" in the mvc pattern. You should avoid anything other than display specific logic in your views. On a side note, can you post your view (or parts of it) so I can get a better understanding of your problem? Commented Jun 26, 2012 at 23:05
  • This is what I'm trying to do in the View: @ObjectContext.GetObjectType(item.TimelineEntry.Document.GetType()).Name.ToString(); Commented Jun 26, 2012 at 23:19
  • So what is probably happening is some other assembly you have referenced in your project is referencing a different version of the entity framework hence why you are getting the the message in your build display. Is your application just one Project file or are there multiple projects in the same solution that all may or may not reference the entity framework? Commented Jun 26, 2012 at 23:27
  • 1
    I followed your advice and just added a property in the model to access the information I need. Still bothered by the issue of the versions and why I can't include system.data.objects in my views. Commented Jun 27, 2012 at 16:45

3 Answers 3

28

You can build your solution in diagnostic mode to get more detailed information about the error.

Open the VS Options dialog (Tools > Options), navigate to the "Projects and Solutions" node and select "Build and Run". Change the MS Build project build output verbosity to Diagnostic.

Have a look here.

Sign up to request clarification or add additional context in comments.

2 Comments

Diagnostics mode tells you exactly which dlls are pulling in the other versions too. Very helpful.
Just a note, once you get the build output do a search for the word "conflict" in the output window and you will find the issue.
3

If you look at the build message, it states the 4.0 version of the .net framework is referenced... Is there a setting in your project file or web/app.config specifying a conflicting version of the .net framework?

Are you familiar with fuslog? you can set it up to log all assembly bindings that .net is doing while running your application. You should then be able to see detailed information on what is getting bound when. If you still can't figure it out, you can always do a binding redirect on that .dll in the web.config.

http://msdn.microsoft.com/en-us/library/eftw1fys.aspx -- binding redirects

http://msdn.microsoft.com/en-us/library/e74a18c4(v=vs.71).aspx -- fusion log viewer

Set up fusion logger and take a look at what the output is. If you don't get an answer from that, try the binding redirect (which would give you at least a temporary solution).

5 Comments

I'm not sure how to find out what is referencing what. The project properties are referencing .Net 4.5. How do I track this down? There's only one System.Data.Entity DLL in the references.
Looks like the view is accessing the Entity Framework 5 Version of system.data.entity and the controller is accessing version 4, which has system.data.objects. How do I 1) make sure the whole project is using the new assemblies. 2) Get to object context on the version 5 EF?
Weird - the model has no problem accessing objectcontext either.
@YHaber I updated my answer with some helpful information that might help you track down your binding problems. Let me know if you figure something out!
@YHaber Did you end up figuring this out using the tools mentioned?
0

In the directory I was publishing to, there was a folder named aspnet_client. I moved it (instead of deleting it), republished, and it worked. I'm not sure why that folder decided to give me trouble out of the blue.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.