简体   繁体   中英

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.

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

Use full path to dll For .NetFramework #r "C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework.NETFramework\\v4.7.2\\Facades\\System.Linq.dll"

For .NETCore #r "C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework.NETCore\\v4.5\\System.Linq.dll"

Chech file locations and adjust version numbers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM