42

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.

valiano
  • 16,433
  • 7
  • 64
  • 79
Caley Woods
  • 4,707
  • 4
  • 29
  • 38
  • 2
    What exactly is the question you are trying to ask? – Goronmon Dec 02 '10 at 19:40
  • So you follow the warning and remove the reference or retarget to at least .NET 4.0. What's the issue? – jason Dec 02 '10 at 19:45
  • The issue was I wasn't sure how to remove the reference, all fixed now. – Caley Woods Dec 02 '10 at 20:02
  • 4
    Do you see how nowhere in your question did you say "How do you remove a reference from a project in Visual Studio 2010" and you had a lot of extraneous noise that had nothing to do with the question that you seem to have really wanted answered? – jason Dec 02 '10 at 20:28

2 Answers2

75

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.

Matt Greer
  • 60,826
  • 17
  • 123
  • 123
  • 21
    Thank you Matt, your answer helped me decide what I wanted to do rather than just read people bitching about someone doing something incorrectly and NOT helping at all. well done. – shawty Oct 28 '11 at 12:16
  • I ran up against the same problem with my bright new shiny VS2010. Your answer was a "bingo" - thank you! – paulsm4 Nov 01 '11 at 23:42
  • 3
    Does anyone know what the reasoning was behind adding that reference by default in the first place? – Josh Kodroff Nov 14 '12 at 16:15
  • 4
    @JoshKodroff, it appears to support the `dynamic` keyword and run-time compilation. [Here's a relevant answer from a different question.](http://stackoverflow.com/a/2460934/897559) – Travis Watson Apr 01 '13 at 17:11
  • 1
    Hey gang. I just ran into this. For me, this is in the **Web.config** of my application. It is the only entry under the `` section. Do I not need that section at all under .NETFramework, Version 3.5? –  Mar 27 '14 at 01:42
  • Duh, how do you remove the reference? – 0xG Apr 04 '19 at 21:54
2

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.

DerAdler
  • 21
  • 1