Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The primary reference "Microsoft.CSharp", which is a framework assembly, could not be resolved in the currently targeted framework

I started a new winforms project, fairly simple, has a few labels, text boxes, and a button. All code is running fine. I forgot to change the framework version from 4 (using VS 2010) to 3.5 before I created the app and when I changed it to 3.5 or 3.5 client profile I get the following warning:

The primary reference "Microsoft.CSharp", which is a framework assembly, could not be resolved in the currently targeted framework. ".NETFramework,Version=v3.5". To resolve this problem, either remove the reference "Microsoft.CSharp" or retarget your application to a framework version which contains "Microsoft.CSharp".

It's not a huge amount of trouble to recreate this with a 3.5 setting from the start and I'm fairly sure I'm not using anything from the 4 framework that I need.

like image 815
Caley Woods Avatar asked Dec 02 '10 19:12

Caley Woods


2 Answers

In most/all project templates in VS 2010 for .NET 4, the Microsoft.CSharp assembly reference is added. So when you created the project you were given this assembly reference automatically. You shouldn't have any problems just removing the reference.

like image 154
Matt Greer Avatar answered Oct 31 '22 08:10

Matt Greer


I just wish to add my experience too. In my case, removing the Microsoft.CSharp reference was enough just to take the warnings away and compile the solution, however while using the console I got some errors still referring to the missing frameworks reference. I then created an empty new console project; by default the ".NET FrameWork 4 Client Profile" was set, so I immediately replaced it with the ".NET Framework 3.5 Client Profile" option and saved. Then I copy&paste all my code from the original project and add all the references I used in the project. Then I renamed the solution, namespace, assembly name, etc, like my original project and compiled it. No warnings/errors and everything was OK.

I then tried to use the console application (on an environment with just the .NET 3.5) and everything worked flawless ^_^ (instead, just changing the .NET reference from 4 to 3.5 in the project proprieties, I got the errors I said above).

Hope this may help those having problems while just changing the "targeted framework" and removing the Microsoft.CSharp reference in an existing project.

like image 28
DerAdler Avatar answered Oct 31 '22 08:10

DerAdler