"System.NotSupportedException: Can not change a read-only list or collection" Random issue

"System.NotSupportedException: Can not change a read-only list or collection" Random issue

Old forum URL: forums.lhotka.net/forums/t/11772.aspx

Pravin posted on Tuesday, January 08, 2013

I am getting this issue while setting value to property.

here is scenario:- 

I have a async rule for one property and and while setting this property in code I get set or load failed for property issue I checked stack trace and seems exception is of "System.NotSupportedException: Can not change a read-only list or collection".I think this is related ti Context.results collection in async rule and it is giving error at context.Results.Add(…) line .

Anyone already have acrossed such issue ? Please help

 PS - i am not getting this issue every time i went to set value t property this is very randomly generated. 

Thanks in advance

JonnyBee replied on Wednesday, January 09, 2013

Which version of CSLA do you use and runtime (NET, SL, WinRT)?

Can you show us the code for the async rule and how you set the property in code?

Pravin replied on Wednesday, January 09, 2013

Thanks JonnyBee for reply .

I am using 4.1 SL version

code is here

async rule -

 protected override void Execute(RuleContext context)



(s, r) =>




if (r.Exception != null)






else if (!r.Data.Exists)





new RuleResult(











if (!restrictPropertyChange)


















I am not setting property inside rule

Property is set in Business object and on which this async rule is get triggred

 if (bookGroupInfo != null) this.Entity.SecondaryBookGroupId = bookGroupInfo.Id;






so randomly I am getting Property load or set failed for property SecondaryBookGroupId issue for this line(while setting property)

If i use alternate way and remove async rule then there is no issue.issue comes randomly when i use async rule.

Thanks in advance..   

JonnyBee replied on Thursday, January 10, 2013

Could it be the LanguageService that gives the exception?

try to replace it with a static string and see if you still get the exception? 

Russ replied on Thursday, January 10, 2013

Could this be the race condition that was occurring when multiple business objects were created in rapid succession. This was fixed in RC1 4.5.4-121017:


Fix bug with race condition in rule initialization code for both Authz and Business rules


JonnyBee replied on Thursday, January 10, 2013

I don't believe this is the case. The race condition occurred when rules was initializing when first/second instance was created at the same time.

The original post identified the exception occurred in context.Results.Add

Pravin replied on Thursday, January 10, 2013

LanguageService will not be point for Exception.but even though i replaced and test with hardcode string and i am still getting issue. It is not consistent issue

JonnyBee replied on Friday, January 11, 2013

context.AddErrrorResult creates and adds a new item to Results, defined as:


    private List<RuleResult> _results;
And there is no way that this is going to throw the given exception. 
So it could be that the actual line is incorrect and that it is context.Complete() that causes the exception.
CSLA 4.1 has a known bug there - http://www.lhotka.net/cslabugs/edit_bug.aspx?id=1026 
This was fixed in CSLA 4.3  


Copyright (c) Marimer LLC