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
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?
Thanks JonnyBee for reply .
I am using 4.1 SL version
code is here
async rule -
protected override void Execute(RuleContext context)
{
factory.BookGroupExistsBeginExecute( (s, r) => { if (r.Exception != null)
{ context.AddErrorResult(r.Exception.ToString()); } else if (!r.Data.Exists)
{ context.Results.Add( new RuleResult(
RuleName, this.PrimaryProperty,
LanguageService.GetText("BookGroupsNotExist")));
} if (!restrictPropertyChange)
{ target.LoadProperty(FromAsyncRuleProp, true);
context.Complete(); } else { context.Complete(); } }, target.SelectedCompanies); }
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..
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?
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:
1107 |
Fix bug with race condition in rule initialization code for both Authz and Business rules |
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
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
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