我正在使用
JSON.NET与
LinqBridge .dll合并.LinqBridge允许从.NET 2访问Linq.如果我尝试使用Linq,即使在导入System.Linq后,我收到以下错误:
Error 13 Could not find an implementation of the query pattern for source type 'int[]'. 'Where' not found. Are you missing a reference to 'System.Core.dll' or a using directive for 'System.Linq'? C:\Users\chrisl\Desktop\SoftTokens\Windows Desktop Soft-Token\Program.cs 27 25 WindowsSoftToken
如果我尝试包含LinqBridge,那么因为JSON.NET已经包含它,我会收到此警告.另外,我已经两次包含相同的组件,这是低效的:
Warning 2 The predefined type 'System.Action' is defined in multiple assemblies in the global alias; using definition from 'c:\Users\chrisl\Desktop\SoftTokens\Windows Desktop Soft-Token\libs\Newtonsoft.Json.Net20.dll' WindowsSoftToken
如果我在对象浏览器中浏览Newtonsoft.Json.Net20,我看到System.Linq显示为空,即使我选择了显示隐藏的类型和方法.
是否可以从JSON.NET DLL访问Linq或抑制错误消息?
解决方法
在LINQBridge程序集中提供LINQ查询运算符的Enumerable静态类仍在System.Linq命名空间中公开.
您仍然需要按照第一条错误消息中的指示使用System.Linq的using指令.
更新:
事实证明,合并到Newtonsoft.Json.Net20.dll的LINQBridge程序集已经“内化”,我最初没有注意到.这意味着您的代码无法引用编译器“实现查询模式”所需的Enumerable类型.因此,您必须自己引用LINQBridge程序集,但是如您所述,您会收到有关重复定义的警告.
您可以通过转到项目属性的“构建”选项卡来禁用重复的类警告,并在“抑制警告:”框中输入“1685”.