'Accidentally deleted System.Core Reference

I have accidentally deleted the System.Core reference from the References tab on the application settings and I want to know how I can add it again.

You may think it is as simple to add as it is to delete but each time I try and add it through the "Add..." button it comes up with this error:

"A reference to 'System.Core' could not be added. This component is already automatically referenced by the build system."

My problem is that now it's gone, I cannot do simple lines of code such as My.Computer or Application or even Me...

How do I re-add it?

And for those who to want to know how I deleted it. I was deleting references that were unused by my application and I went a bit delete happy and clicked it too fast and too many times. I was able to add the rest of the references find but it's just the System.Core.



Solution 1:[1]

I have figured out the problem and fixed it.

By opening the project file in Notepad and adding the following lines to the file and saving it, the System.Core reference was restored:

<ItemGroup> 
  <Reference Include="System.Core" /> 
</ItemGroup>

The project file can be found in: Documents\Visual Studio 2010\Projects\Your Application\Your Application\Your Application.vbproj

After this, restart Visual Studio if it's not already closed and re-open the project. If, like me, you find that you have errors such as "restart() is not a member of Your Application.My.MyApplication" or something of that nature.

Fixing this is also easy; go into the application settings and then go into the references tab. In the Imported Namespaces menu scroll down until you see:

System.Windows and System.Windows.Forms

If these are un-ticked then tick them and then the errors should go away.

Hope this helps anyone having the same problem I've had!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 TonyArra