2

I have a project written in VS2012/.Net 4.5 that is essentially a bog-standard, database-first Entity Framework 5 entity model and context, and associated business domain classes. That all works fine when I'm referencing the built assembly from a VS2012/.Net 4.5 application (I've used it successfully with an MVC website and with integration test projects). However when I try to use the exact same assembly from a VS2010/.Net 4 application on the same machine, Visual Studio will add a reference to the assembly with no problem, the classes will also show up under Intellisense (I can add a using statement, for example), but as soon as I try to build the project I get the following error:

Warning 3 The primary reference "MyDotNet45Assembly" could not be resolved because it was built against the ".NETFramework,Version=v4.5" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.0".

My understanding (e.g. from Scott Hanselman here) was that .Net 4.5 was an in-place upgrade to .Net 4.0, so I can't understand why I can't call an assembly created for the newer version. What am I missing or misunderstanding? I can't believe I'm the only person who has hit this issue, but I'm genuinely struggling to find anything on the web that explains what's going on.

I've looked at a number other questions on StackOverflow, none of which seem to quite cover what I'm after, e.g: Using EF4.0 in a .Net 3.5 app Using a .Net 4.0 assembly in a .Net 4.5 project

Community
  • 1
  • 1
Griff1000
  • 21
  • 2
  • 1
    When you target 4.0 in VS2010 then you'll get a hard guarantee that the project will actually run on a machine that has 4.0 installed. In other words, it will not accidentally use added assemblies and classes that are only available in 4.5. Clearly that appears to be a problem or you would have just changed the target version in VS2012 to 4.0. Trying to teach VS2010 new tricks, like targeting 4.5 just isn't worth your time. Simply open the project in VS2012 and be done with it. – Hans Passant Aug 21 '13 at 18:50
  • Thanks Hans. I was hoping to avoid that since my company has hit a bit of a roadblock part-way through rolling out VS2012. I'll have a look at re-doing the EF model on .Net 4, which is a bit of a pain as I'll lose all that lovely Enum support. I'll give it a day to see if anyone comes up with any magic solution, and if not I'll mark your reply as answer. Thanks for your help. – Griff1000 Aug 22 '13 at 07:56

0 Answers0