The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to ‘Join’.

Let’s start by saying the code in this example is a really silly, but it’s a great reference for the matter at hand. Let’s assume you need to do a join on multiple columns and you’ve double checked and triple checked that the types are all the same, but you’re stuck with the following error:

The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to ‘Join’.

The problem is related to anonymous types. The type initializer cannot infer the same anonymous type because the names are not the same. The solution is simple: specify the name in one of the expressions such that they are the same and the problem is solved.

Problem Code

linqJoin1

Solution

linqJoin2

Now that the types AND the names are the same, the anonymous type initializer can create the same anonymous type and properly facilitate the join.

I hope this helps someone.

Happy coding,

Tom Hundley
Elegant Software Solutions, LLC

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s