Why cant a .net 4.0 project reference a 4.5 assembly?

送分小仙女□ 提交于 2019-12-08 15:13:28

问题


I am working on a project targeting .NET 4.0 and now I need to reference a third party dll which was built targeting .NET 4.5. It seems that visual studio does not accept that? Why? VS shows me that dll name does not exist in current context.


回答1:


Because you are referencing to the higher version. Microsoft can be backcompatible, but not "future compatible". You need to convert your entire project to higher vesion, in order to be able to use that binary.

Don't know what tecnology you are talking about exactly, but if that asp.net, consider that in vNext you are able to deploy your own version of the cloud clr on the server. So you may have 2 versions of your app, one targetting 4.5, other 4.0.

Introducing vNext. Repeat, if this concerns you.




回答2:


A project targeting .NET 4.0 can run on the 4.0 runtime. A DLL targeting .NET 4.5 cannot.

If allowed; you would be able to build projects that appear to work in 4.0, and fail when they tried to load the 4.5 components.

You can reference things going the other way; as a 4.0 DLL can be loaded in the 4.5 runtime.

You will need to either request a 4.0 version of the DLL from the third party; or target .NET 4.5.




回答3:


The application domain will be running under the 4.0 runtime and so cannot reference newer dotnet version, only the reverse is true.

4.5 is a different .net runtime so it is not possible to load a 4.5 in an older version.

You must remember that the runtime will need to interpret the Intermediate Language (IL) into machine code. If the IL was created on 4.5 a 4.0 runtime would have no idea how to interpret it.




回答4:


Create a console app in 4.5 and then execute a cmd from 4.0 to get the data you needed from 4.5, might be a quick solution. Not idea but it does the job :)



来源:https://stackoverflow.com/questions/26973133/why-cant-a-net-4-0-project-reference-a-4-5-assembly

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!