【问题标题】:Unable to access System.Linq even though System.Core.dll is included即使包含 System.Core.dll 也无法访问 System.Linq
【发布时间】:2020-08-16 08:45:24
【问题描述】:

我有这个控制台应用程序:

namespace LinqTestFramework
{
    using System.Collections.Generic;
    
    public class Program
    {
        static void Main(string[] args)
        {
            var dict = new Dictionary<int, string>()
            {
                { 1, "David" }
            };            
        } //breakpoint set here: Watch window: System.Linq.Enumerable.Where(dict, x => true)
    }
}

namespace LinqTestFramework
{
    using System.Linq;
    public class SomeClass
    {
        public void SomeMethod()
        {
            var valuesBelowFour = Enumerable.Range(0, 10).Where(x => x < 4);
        }        
    }
}

我可以从 ILSpy 中看到包含这些方法的 System.Core dll:

我试图在调试期间从 Watch 窗口运行以下命令:

System.Linq.Enumerable.Where(dict, x => true)

但我收到此错误:

错误 CS0234:类型或命名空间名称“Linq”不存在于 命名空间“系统”(您是否缺少程序集引用?)

为什么我无法访问System.Linq.Enumerable 中的扩展方法?

【问题讨论】:

  • 您使用的是什么 .net 版本?如果我是正确的,在 .net core 2.x 中有一个错误
  • @Jodn .NET Framework 4.7.2

标签: c# linq dll .net-4.7.2


【解决方案1】:

它似乎需要一个使用 Linq 方法来加载它的方法调用。所以我尝试了下面的代码,现在它正在工作

public class Program
    {
        static void Main(string[] args)
        {
            var dict = new Dictionary<int, string>()
            {
                { 1, "David" }
            };
            
           var n = dict.Keys.Select(x=>x);

        } //breakpoint set here: Watch window: 
}

【讨论】:

  • 感谢您的回答。但是,我正在寻找为什么会发生这种情况的答案,而不是解决方法。
  • 检查调试>模块。如果没有 LINQ 方法调用,它不会加载 System.Linq.dll 的调试符号。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-19
  • 2021-08-20
相关资源
最近更新 更多