【问题标题】:Accessing LinqBridge from JSON.NET dll从 JSON.NET dll 访问 LinqBridge
【发布时间】:2011-07-27 06:38:44
【问题描述】:

我正在使用 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 显示为空,即使在我选择了 Show hidden types and methods 之后也是如此。

是否可以从 JSON.NET dll 访问 Linq 或抑制错误消息?

【问题讨论】:

  • 您的目标是什么版本的 .NET 框架?什么版本的 JSON.Net?
  • @Mike:JSON.NET 4.0 和目标 .NET 2
  • 我已经为这个案例发布了一个问题。我有同样的问题,此时我决定在没有 LinqBridge.cs 的情况下重新编译 Json.NET 项目:github.com/JamesNK/Newtonsoft.Json/issues/8

标签: json.net linqbridge


【解决方案1】:

在 LINQBridge 程序集中提供 LINQ 查询运算符的 Enumerable 静态类仍公开在 System.Linq 命名空间中。

您仍然需要按照您的第一条错误消息中的指示使用 System.Linq 的 using 指令。

更新:

事实证明,合并到 Newtonsoft.Json.Net20.dll 中的 LINQBridge 程序集已被“内部化”,我一开始并没有注意到。这意味着您的代码无法引用编译器“实现查询模式”所需的 Enumerable 类型。因此,您必须自己引用 LINQBridge 程序集,但随后您会收到有关重复定义的警告。

您可以通过转到项目属性的“构建”选项卡并在“禁止警告:”框中输入“1685”来禁用重复类警告。

但最好的办法是从源代码构建您自己的 JSON.net 版本,而不在 LINQBridge 中合并。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-20
    • 1970-01-01
    • 2013-04-15
    • 2012-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多