Troubleshooting .NET Framework Targeting Errors
Visual Studio lets you distribute a lightweight .NET Framework runtime, known as the .NET Framework 4 Client Profile, which is a runtime that includes just a subset of the binaries that are contained in .NET Framework 4. By using .NET Framework 4 Client Profile, you can distribute a smaller .NET Framework library to the users of your application so that they can run the application even if the full .NET Framework 4 is not installed on their systems.
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.
For more information about the .NET Framework 4 Client Profile, see .NET Framework Client Profile and How to: Target a Specific .NET Framework Version or Profile.
If your application tries to reference functionality that is contained in an assembly or dependent assembly that is not included in the .NET Framework 4 Client Profile, run-time error messages may occur. The exact message depends on where the referenced functionality is located. To eliminate such errors, you can either remove the incorrect assembly reference from the project, or set the project to target the full .NET Framework version 4 instead of the .NET Framework 4 Client Profile subset library.
You can create applications that reference projects or assemblies that target different versions of the .NET Framework. For example, if you create an application that targets the .NET Framework 4 Client Profile, that project can reference an assembly that targets .NET Framework version 2.0. However, if you create a project that targets an earlier version of the .NET Framework, you cannot set a reference in that project to a project or assembly that targets the .NET Framework 4 Client Profile or the .NET Framework 4. To eliminate the error, make sure that the profile targeted by your application is compatible with the profile targeted by the projects or assemblies referenced by your application.
If you change the target version of the .NET Framework for your application, Visual Studio changes some of the references. However, you must also make some manual updates. For example, if you create an application that has resources or settings that rely on the .NET Framework 4 Client Profile and then change the application to target .NET Framework 3.5 SP1, you might see one of the previously mentioned errors.
As a workaround for application settings, in Solution Explorer, click Show All Files, and then edit the app.config file in the Visual Studio XML Editor. Change the version in the settings to match the version of the .NET Framework. For example, you can change the version setting from 188.8.131.52 to 184.108.40.206. Similarly for an application that has added resources, in Solution Explorer, click Show All Files, expand My Project (Visual Basic) or Properties (C#), and then edit the Resources.resx file in the Visual Studio XML Editor. Change the version setting from 220.127.116.11 to 18.104.22.168.
If your application has resources such as icons or bitmaps or has settings such as data connection strings, you can also remedy the problem by removing all the items on the Settings page in the Project Designer and then re-adding the required settings.
In some cases when you retarget a project to a different version of the .NET Framework, your references may not resolve properly, A common cause for this is explicit fully-qualified references to assemblies. You can fix this by removing the references that do not resolve, and then adding them back to the project. Alternatively, you can edit the project file to remove references of the form:
<Reference Include="System.ServiceModel, Version=22.214.171.124, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL" />
and replace them with the simple form:
<Reference Include="System.ServiceModel" />
After you close and reopen your project, you should also rebuild it to ensure that all references are correctly resolved.