9

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.

Jeff
  • 2,191
  • 4
  • 30
  • 49
  • Looks [like this](http://stackoverflow.com/a/19636730/17034), you do need to document your type of project of course. Use connect.microsoft.com if you think it needs to work. – Hans Passant Apr 19 '16 at 15:57
  • @HansPassant I'm not exactly sure how to map that answer to this question, but I tried execute `System.Reflection.Assembly.Load(...)` from the interactive window. I'm getting red squigglies under `System` anywhere I type it, even trying a using statement `using System.Reflection;` - is that useful at all? – Jeff Apr 19 '16 at 16:06
  • Does it work on the command-line interface (`csi`)? – Paulo Morgado Apr 20 '16 at 10:48
  • @PauloMorgado which part do you mean? Is the 'command-line interface' something different from the interactive window I'm describing? I don't know of another window to use this feature. – Jeff Apr 20 '16 at 14:08
  • It's always clean. You don't `#reset` it. – Paulo Morgado Apr 21 '16 at 00:33
  • @PauloMorgado I didn't enter `#reset` myself. That happens when I select `Initialize Interactive with Project` from the context menu of the project in Solution Explorer. – Jeff Apr 21 '16 at 13:26
  • @HansPassant please take a look at my answer below - if you're interested, I'd love to get your take on this. – Jeff Jun 21 '16 at 20:33

3 Answers3

8

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.

Jeff
  • 2,191
  • 4
  • 30
  • 49
3

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!

Cheshire Cat
  • 1,941
  • 6
  • 36
  • 69
0

I had an incompatible package referenced, which caused this error. Overlooked during package upgrade. Removed the reference & fixing namespaces did the trick.

JensG
  • 13,148
  • 4
  • 45
  • 55