CRM 4 – Can’t assign FilterExpresion it’s read only!

I am up to my eyes in workflows today and I was trying to do a query to retrieve some items, so I had to refresh myself how to do it in CRM 4.  I thought I would try the sample code and when I pasted it a bit in, I got this error


Property or indexer ‘Microsoft.Crm.Sdk.Query.FilterExpresssion.Conditions’ cannot be assigned to — it is read only

The problem line of code was this one

filterPrincipal.Conditions = new ConditionExpression[] {conditionPrincipal};

There is nothing more frustrating when the sample code doesn’t work or compile.  The answer was oddly simple and I assume they must have changed how it worked sometime after CRM 4 was released and maybe I haven’t updated my sample code.

Anyway as the message said read only I used a bit of of intellisense to see what I could do with the condition and found there was an add.

So instead of assigning the Condition you have to add it like this.



Leave a Reply

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

You are commenting using your 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.