Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS2015 C# interactive: error CS7069: Reference to type 'Object' claims it is defined in 'System.Runtime', but it could not be found

I just updated to VS2015 Update 2, and started playing around with the C# interactive window. I wanted to use a static method in a static class in one of my .NET 4.0 targeted library projects, so I right-clicked on the project in Solution Explorer, and selected Initialize Interactive with Project. The output in the interactive window looks like this (I replaced some of the full paths with '..' for brevity):

#reset
Resetting execution engine.
Loading context from 'CSharpInteractive.rsp'.
#r "..\src\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll"
#r "..\src\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.dll"
#r "..\src\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll"
#r "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.dll"
#r "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Core.dll"
#r "..\src\packages\Microsoft.Bcl.1.1.8\lib\net40\System.IO.dll"
#r "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Net.dll"
#r "..\src\packages\Microsoft.Bcl.1.1.8\lib\net40\System.Runtime.dll"
#r "..\src\packages\Microsoft.Bcl.1.1.8\lib\net40\System.Threading.Tasks.dll"
#r "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Web.dll"
#r "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Xml.Linq.dll"
#r "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Data.DataSetExtensions.dll"
#r "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Microsoft.CSharp.dll"
#r "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Data.dll"
#r "C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies\System.Net.Http.dll"
#r "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Xml.dll"
#r "MyDll.dll"
using MyDll;
(1,7): error CS7069: Reference to type 'Object' claims it is defined in 'System.Runtime', but it could not be found

Note the nasty little line at the end, blocking my path to happiness:

(1,7): error CS7069: Reference to type 'Object' claims it is defined in 'System.Runtime', but it could not be found

I get intellisense for the classes in the project, but I get the same error any time I try to run a statement. I can still run simple things like:

> string.Format("No one knows my {0}", "suffering")
"No one knows my suffering"
>

Anyone have any ideas about why this is happening or how to fix it? I'll update this question with any [un]successful suggested fixes.

like image 725
Jeff Avatar asked Apr 19 '16 15:04

Jeff


2 Answers

What ultimately fixed it for me was entering this right in the C# Interactive window.:

#r "System.Runtime"

If there's anyone that can provide a thorough background explanation as to why this worked, I'd love to give you the accepted answer. I just got lucky.

like image 139
Jeff Avatar answered Nov 16 '22 01:11

Jeff


While it might seem a little late to add an answer, it's actually still a possible current issue with Visual Studio 2019 (v16.9.4), or at least it was for me...

In my case it was not related to a reference to a .NET Framework standard package but with a reference to one of my projects in the solution.

I successfully solved the issue by following these steps:

  1. Remove the package/project reference from the project where the issue resides.

  2. Clean the issued project (for more cleanup, you can also delete the bin/obj folders from Explorer).

  3. If the reference is to a project, Clean and Rebuild the referenced project.

  4. Add again the reference to the package/project and rebuild all in the solution.

Hope it helps!

like image 25
Cheshire Cat Avatar answered Nov 16 '22 02:11

Cheshire Cat