Monday, April 13, 2015

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

This and this both suggest that this problem may rear its head when one deletes System.Core (and/or maybe mscorlib) as a reference and tries to readd it. A suggested fix is to close Visual Studio 2013, open a .csproj file in Notepad, find this line...

<Reference Include="System" />

 
 

...and add this line below it...

<Reference Include="System.Core" />

 
 

...and yet that doesn't work for me because I sense something sinister of a greater scope. I think the fact that the application I am working on, which used to be of C# 2.0, has been upgraded to C# 4.5.1 is causing strangeness. I have no real evidence to back up my theory, I just don't see what else gives. In my case when I attempt the fix System.Core appears as a reference in the Solution Explorer when I open Visual Studio back up again, but when I try to bring in a using directive that makes use of System.Core it appears as red and angry in Visual Studio and does not compile. I should be able to dot out to things which theoretically exist off of a dynamic type like so:

dynamic dateTimeOffset = (dynamic)DateTimeOffset.UtcNow;
DateTime dateTime = dateTimeOffset.DateTime;

 
 

...but I cannot. I get the squiggly red line beneath the dateTimeOffset.DateTime and when I put my mouse over it I am told:

One or more types required to compile a dynamic expression cannot be found. Are you missing references to Microsoft.CSharp.dll and System.Core.dill?

 
 

I can hack around the shortcoming like this:

dynamic dateTimeOffset = (dynamic)DateTimeOffset.UtcNow;
DateTime dateTime = ((DateTimeOffset)dateTimeOffset).DateTime;

 
 

...but I shouldn't have to. What am I missing?

 
 

Addendum 1/29/2019: DateTimeOffset.Now is also a thing.

No comments:

Post a Comment