6

I am curious as to the mscorlib reference in different project templates.

When I create a WPF project, I cannot find the mscorlib file in the reference folder. I think it is referenced by default.

When I create a Silverlight project, I can find it in the folder. It links to the Silverlight framework. Then I tried to delete it and of course it cannot be compiled. Then I tried to re-add this assembly to the reference again; it cannot be added and cannot be compiled anymore. It's weird.

When I create a MonoDroid project, I can still find the mscorlib reference. But after I deleted this reference, the project still can be compiled; but I'm not sure if it runs fine.

Does anyone knows what causes this behavior?

Thanks, Howard

Daniel A.A. Pelsmaeker
  • 47,471
  • 20
  • 111
  • 157
Howard
  • 3,638
  • 4
  • 32
  • 39

2 Answers2

8

Just so someone does not have to google it. I was missing the mscorlib and found the exact way CuiPengFei suggested to do this in the project file, here:Microsoft Connect Feedback in the workaround which was posted by James Wightman on 12/9/2009 at 2:52 AM below:

As I said in the bug report, one workaround is to manually add the reference back into the project manually by editing the csproj file using (for example) notepad:

Find this section in the csproj file - obviously if you have different/additional references that's what you're looking for:

<ItemGroup>
 <Reference Include="System.Windows" />
 <Reference Include="system" />
 <Reference Include="System.Net" />
 <Reference Include="System.Xml" />
 <Reference Include="System.Windows.Browser" />
</ItemGroup>

Add a line for each of the missing references - in this case, mscorlib and System.Core - and your csproj file should now look something like this:

<ItemGroup>
 <Reference Include="mscorlib" />
 <Reference Include="System.Core" />
 <Reference Include="System.Windows" />
 <Reference Include="system" />
 <Reference Include="System.Net" />
 <Reference Include="System.Xml" />
 <Reference Include="System.Windows.Browser" />
</ItemGroup>
Brian
  • 688
  • 5
  • 18
  • This should be the accepted answer here. I would also like to add that after including the reference you may need to restart Visual Studio before it will start working – Bassie Jul 08 '16 at 15:09
6

This is a known issue that will not be able to fix for VS2010. The workaround is to edit the project file and manually re-add the reference.

Cui Pengfei 崔鹏飞
  • 8,017
  • 6
  • 46
  • 87