Posted on 31. March 2011

“Value cannot be null.Parameter name: attributeName” when running Linq query with join

If you run the following query using the CRM 2011 Linq provider (I'm using Linq pad here):

from u in SystemUserSet
where u.Id == new Guid("f19f4c09-965b-e011-ab82-000c2957f385")
select u
All is well. However, if you add a join:
from u in SystemUserSet
join t in TerritorySet
on u.TerritoryId.Id equals t.TerritoryId.Value
where u.Id == new Guid("f19f4c09-965b-e011-ab82-000c2957f385")
select u

You will get the following exception:

System.ArgumentNullException: Value cannot be null.
Parameter name: attributeName

Looking at the Query Expression created, you will see:

<ConditionExpression>
       <AttributeName i:nil="true" />
        <Operator>Equal</Operator>
        <Values xmlns:d5p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
          <d5p1:anyType xmlns:d6p1="http://schemas.microsoft.com/2003/10/Serialization/" i:type="d6p1:guid">f19f4c09-965b-e011-ab82-000c2957f385</d5p1:anyType>
        </Values>
      </ConditionExpression>

The problem seems to do with the way that the Linq provider resolves attribute names on the Id field.

You need to change the query to be (specifying the Id parameter explicitly):

from u in SystemUserSet
join t in TerritorySet
on u.TerritoryId.Id equals t.TerritoryId.Value
where u.SystemUserId == new Guid("f19f4c09-965b-e011-ab82-000c2957f385")
select u

Comments

pingback ask.techwikihow.com
12:21 PM on Tuesday, October 29, 2013

Pingback from ask.techwikihow.com

FaultException attributeName LINQ Where ID clause | TechwikiHow

pingback nishantrana.wordpress.com
8:06 PM on Tuesday, May 27, 2014

Pingback from nishantrana.wordpress.com

attributeName error while using join in LINQ in CRM. | Nishant Rana's Weblog

Nishant Rana’s Weblog Nishant Rana’s Weblog
9:48 PM on Wednesday, November 02, 2016

attributeName error while using join in LINQ in CRM.

I recently wrote a LINQ using joins, all seemed fine, but was still getting the attributeName exception

Comments are closed