代码改变世界

.NET Framework 4 与 .NET Framework 4 Client Profile

2012-07-24 07:58  左眼微笑右眼泪  阅读(336)  评论(0编辑  收藏  举报

     最近在项目中遇到了一个问题,本身我已经引用了另外一个程序集,可是编译器还是报错,说找不到命名空间,但是我明明引用了,找了半天,终于找到问题的所在了。查看项目的属性时,发现它的Framework 版本是.NET Framework 4 Client Profile,把它改成.NET Framework 4就可以了。在网上查了一些相关的资料,介绍了这两者的区别。

     原来是因为微软的.NET Framework 太大了,有几百兆,这就导致在开发的过程很不方便,给用户安装的时候,也要附带一个.NET Framework ,这样就显得很麻烦,微软为了解决这个问题,就对.NET Framework 进行减肥,把一些核心的功能抽提出来,这就是.NET Framework Client Profile。而其他一些不常用的功能则没有放进来。Profile是从.NET Framework 3.5开始提供的。.NET Framework 4 Client Profile在3.5的基础上又做了改进。通过这,我们就知道,其实。.NET Framework 4 Client Profile是。.NET Framework 4 的一个子集。所以如果你的项目是Framework 4 Client Profile,那么你就不能引用Framework 4版本的组件。因为.NET Framework 4中的部分功能在NET Framework 4 Client Profile中是没有的,所以就会报错。

      在微软的官网上会看到其他一些错误的说明:

When your application targets a particular profile, you might encounter errors if you try to reference an assembly that is not part of that profile. Common errors include the following:

  • The type or namespace name "name" does not exist in the namespace "namespace". (Are you missing an assembly reference?)

  • Type "typename" is not defined.

  • Could not resolve assembly "assembly". The assembly is not listed as part of the "profile" Profile.

These errors can result from different actions. This topic includes descriptions of what might have caused the error and how to resolve the issue.

     如果想知道.NET Framework 4 Client Profile包含哪些内容,没有包含哪些内容,可以参考这个网址。.NET Framework Client Profile

     其他参考资料:

     Troubleshooting .NET Framework Targeting Errors

     What’s new in .NET Framework 4 Client Profile Beta 2

     .NET Framework 4 与 .NET Framework 4 Client Profile