Casebash
Casebash

Reputation: 118742

Accessing LinqBridge from JSON.NET dll

I am using JSON.NET which has the LinqBridge .dll merged in. LinqBridge allows Linq to be accessed from .NET 2. If I try to use Linq, even after importing System.Linq, I receive the following error:

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

If I try to include LinqBridge, then because JSON.NET already includes it, I receive this warning. Additionally, I have included the same component twice, which is inefficient:

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

If I browse Newtonsoft.Json.Net20 in the object browser, I see that System.Linq appears empty, even after I have slected Show hidden types and methods.

Is it possible to access Linq from the JSON.NET dll or to suppress the error messages?

Upvotes: 4

Views: 640

Answers (1)

Mike Schenk
Mike Schenk

Reputation: 1582

The Enumerable static class that provides the LINQ query operators in the LINQBridge assembly is still exposed in the System.Linq namespace.

You still need to have the using directive for System.Linq as directed in your first error message.

Update:

It turns out the LINQBridge assembly that's merged into Newtonsoft.Json.Net20.dll has been "internalized" which I hadn't noticed at first. This means your code can't reference the Enumerable type that the compiler needs to "implement the query pattern." So you do have to reference the LINQBridge assembly yourself, but then you get the warning about duplicate definitions as you mentioned.

You can disable the duplicate class warning by going to the Build tab of your project properties and enter "1685" in the "Suppress warnings:" box.

But what would probably be better would be to build your own version of JSON.net from source without merging in LINQBridge.

Upvotes: 6

Related Questions