Search code examples
c#.netvisual-studioroslynvisual-studio-2017

Why can't I import a C# namespace in interactive mode in VS2017?


I'm trying to import a namespace in interactive mode (the Immediate Window) in VS 2017. However, it doesn't seem to work:

using System.Linq
error CS1525: Invalid expression term 'using'
using System.Linq;
error CS1525: Invalid expression term 'using'
#r System.Linq
error CS1525: Invalid expression term ''
#help
error CS1525: Invalid expression term ''

I looked at the Roslyn GitHub wiki to see if there was a different way to import a namespace in interactive, and I also Googled about my problem. However, I can't find anyone else who had a problem importing namespaces in interactive. Why is this happening, and how can I resolve it? Thanks.


Solution

  • This is only possible in the interactive window, not the immediate window. See these instructions.