Cannot remove System.Core.dll reference from a VS2010 project - by Niranjan U

Status : 

  Won't Fix<br /><br />
		Due to several factors the product team decided to focus its efforts on other items.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 525663 Comments
Status Closed Workarounds
Type Bug Repros 11
Opened 1/19/2010 12:45:29 AM
Access Restriction Public


When I create a new VS2010 project (either a windows forms application or a class library), the project will add a reference to System.Core.dll. If I delete that reference from that project, the project still compiles fine even though there is 'Using System.Linq;' in my code. If I try to re-add the System.Core reference to my project it will throw an exception with this message: "A reference to 'System.Core' could not be added. This component is automatically referenced by the project system and cannot be referenced directly". 
Sign in to post a comment.
Posted by chuckeng on 10/4/2011 at 9:21 AM
@nZeus: The issue you are having is completley unrelated. The message you are receiving is correct, you are missing another assembly reference. You would need to include the assembly which contains the extension methods for the generic list container that you are using.

I don't have your code (and please do not post here, see below), so I can only guess as to what is going wrong. But, the first error cannot be related to System.Core, because even though you remove the reference from the project file and it does not show in the Solution Explorer, we added it automatically for you.

It is more likely that you have not added the appropiate assemblies, or you are not targeting an appropriate framework. In VS2008, it was possible to target 2.0, but still use Linq. In VS2010, this would not be allowed, because true multi-targeting will keep you from building an invalid assembly for a specific target framework.

Please note that I only caught this issue by chance. This issue is in an old database that we no longer use. Once closed, we no longer see the issues.

When reporting an issue, please file a new Connect Bug. If we find that this issue has already been filed, we will attach the issue to the other issue as a duplicate. However, we tend to get a lot of general comments regarding completely different issues.

Hence, general help and questions need to be posted in the forums under the appropriate subject.


Chuck England
Posted by chuckeng on 10/4/2011 at 9:12 AM
@Maximilian Haru Raditya: Yes, the experience is not great. Since System.Core is required, you should never remove it. We fixed this by adding it for you even if you remove the reference. However, we should blindly ignore the fact that when you add it back an error is generated. A lot of this was imposed on us by previous versions which did not understand multi-targeting, and simply did not get cleaned up.

You should not be removing System.Core, as a general rule. If you do, and it really bothers you that it does not show up in the "References" node in Solution Explorer, then you can manually add it back by right-clicking on the project node and selecting Unload. Right-click on the project node again and select Edit. In the editor, copy another reference line (for example, the one for "System") and paste it below the original reference inside the same ItemGroup. Change the reference name to "System.Core". Right-click on the project node and select Reload. Choose "yes" for question to save and reload.

We can't go back to the VS2008 way, as it does not understand multi-targeting. Nor did it understand true "profiles", like the Client Profile of the .NET 4.0 framework. In fact, the issue you are seeing is because the VS2008 system was upgraded to handle multi-targeting, and it is the new set of rules that are rejecting the reference.

We really just did not catch this early enough, and with a really solid understanding of how we could fix it to get a fix prior to our release. But, the fact that you should always reference, and hence never remove "System.Core", made this a Won't Fix, since this is not something that 99% of customers would ever do.

Chuck England
Posted by chuckeng on 10/4/2011 at 9:03 AM
@androidi: It is unfortunate that when you attempt to remove the reference for System.Core that we don't do the right things. However, as the message you saw indicates, System.Core is implicitly referenced. So, the fact that you have removed it, other than physically removing a line from the project file, has not changed the build in any way. There are legitimate scenarios where you might want to be able to do this, but it is a very edgy corner case.

Adding the reference back is super simple if you really want it to be there. Right-click on the project and select Unload. Right-click on the project node again and selct Edit. In the editor, copy another reference line and paste it below the original reference inside the same ItemGroup. Change the reference name to "System.Core". Right-click on the project node and select Reload. Choose "yes" for question to save and reload.

VS2008 did not handle multi-targeting correctly. It would allow you to build things that were not legitimate. With VS2010, we have tried very hard to make sure that if it builds for the target framework, then it will run on the target framework. I can't say I know of any places where this is not true.

In this case, we build even though you removed a reference. You might say, but it should not have built. But, it will run on the targeted framework, and hence should have built. The fact that we have added a "required" refererence for you is somewhat of a broken experience in how it was developed.

Chuck England
Posted by nZeus on 11/9/2010 at 12:48 AM

Without line
<Reference Include="System.Core" />
msbuild gives me an error
error CS0234: The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?)

After i add line
<Reference Include="System.Core" />
i got another error:
error CS1061: 'System.Collections.Generic.List<string>' does not contain a definition for 'Select' and no extension
method 'Select' accepting a first argument of type 'System.Collections.Generic.List<string>' could be found (are you missing a using directive or an assembly reference?)

I can't use linq at all!
My project can't be build!
How can i resolve my problem?
Posted by Maximilian Haru Raditya on 4/26/2010 at 1:44 AM
I'm not actually bothered with inability to remove System.Core.dll reference. But I am bothered with inability to add back System.Core.dll if I accidentally removed it since it throws an error: "A reference to 'System.Core' could not be added. This component is automatically referenced by the project system and cannot be referenced directly".

I can add it back, but I had to manually edit the project file in a text editor/VS editor. This is not a convenience way.

I think VS should decide it this way, just bring back the old VS2008 way. I'm not why the design is changed. Any words?
Posted by androidi on 2/20/2010 at 6:10 PM
I'd like to add that during beta 2 changed NET 4 project to 3.0 then 3.5. I had to manually delete and re-add some references since it didn't automatically work properly atleast back then.

Now I in RC came back to this project and change it back to net 4.0.. And I find I cannot compile after adding dynamic keyword use because System.Core is missing, and I cannot add System.Core back because :

A reference to 'System.Core' could not be added. This component is already automatically referenced by the build system.
Posted by Microsoft on 2/19/2010 at 4:18 PM
The references that are used by projects are determined at build time. Certain references are automatically added and cannot be removed. If you remove them, we still automatically generate the appropriate reference. This is a requirement for Visual Studio 2010, and a change from Visual Studio 2008.

So, in this case, we would want to prevent you from removing the reference in the first place.

Since we just release the RC (Release Canidate), we are too late to make any changes of this size at this point, as it would require a large amount of testing, and could introduce regressions in the code. As such, we have postponed the bug so that we can take a look at this for a future release.

Chuck England
Visual Studio Platform
Program Manager - MSBuild
Posted by Niranjan U on 1/28/2010 at 11:29 PM
What about the behavior when I try to create an application targeted for .NET 3.5 using VS2010? I see that the same behavior is seen even then as well and I think this is incorrect. I think it should give the user the same experience as that of developing in VS2008. So it should not be using System.Core by default.
Posted by Microsoft on 1/25/2010 at 4:05 PM
Thanks for sending us this issue.

I agree that it would be great if we could create some UI that prevented you from being able to delete the reference to System.Core from your project.

There is a work-around to this, which involves cracking opend the project file and adding the reference back manually to the project file. You can find out how the reference should look by copying it from a project file that you create from scratch and inspect.

To edit your project file (or inspect the temp project you are pulling the reference from) you simply right click on the project file and choose "Unload Project" from the context menu. Then right click on the project again (which is now grayed out and unloaded) and choose "Edit {Project Name}" from the context menu. This will bring up the XML editor with your project file. When you are done looking at the project file an making changes, then you can right click on the project again and select "Reload Project" from the context menu. It will prompt you whether or not you want to save changes and/or close the XML file.

Unfortunatley, we are at a point in the cycle where we cannot change the UI. As such, I am resolving this bug as Postponed so that we can look at this again in a future release.


Chuck England
Visual Studio Platform
Program Manager - MSBuild
Posted by Microsoft on 1/21/2010 at 1:29 AM
Thank you for reporting the issue.
We were able to reproduce the issue you are seeing. We are routing this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Microsoft on 1/20/2010 at 3:44 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(