Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reference Component Microsoft.CSharp could not be found

I found this problem on my C# project which I started at Visual Studio 2010, when I go to another PC I use in 2008, I open the project.csproj:

A get or set accessor expected

and warning:

The referenced component 'Microsoft.CSharp' could not be found.

I thought that it was about .NET Framework or Microsoft.CSharp is not located, because it says that:

Could not resolve this reference. Could not locate the assembly "Microsoft.CSharp". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors

but I'm not sure about the problem, can you guys give me a solution? Really appreciated.

like image 371
Pseudorandom Avatar asked Nov 06 '12 13:11

Pseudorandom


People also ask

How do I add a reference to Microsoft CSharp?

You can't add a reference to Microsoft. CSharp. dll as it was not built against the Silverlight runtime. Silverlight projects will only work with Silverlight assemblies.

How do I fix Visual Studio Reference error?

To fix a broken project reference by correcting the reference path. In Solution Explorer, right-click your project node, and then select Properties. The Project Designer appears. If you're using Visual Basic, select the References page, and then click the Reference Paths button.

How do I enable references in Visual Studio?

Press Shift + F12 to find all references.


1 Answers

It sounds like you are targeting .NET 4.0 in the project, and then trying to load it in VS2008 which only targets up to .NET 3.5.

If you need to use the project in VS2008, then you should re-target the project at .NET 3.5:

enter image description here

and then remove any incorrect references (they'll probably have yellow warning triangles on them anyway).

The A get or set accessor expected also suggests you're using new C# syntax, for example dynamic. If you need to target older C# compilers, you'll have to not do that. If you are using multiple IDE versions and it is being a problem, then to ensure you don't do that accidentally you can set the language version for the project via Project Properties -> Build -> Advanced:

enter image description here

like image 146
Marc Gravell Avatar answered Oct 26 '22 22:10

Marc Gravell