Crash Silverlight3, CSLA 3.7.0 when PropertyStatus applied. Possibly Tab-Page issue?

Crash Silverlight3, CSLA 3.7.0 when PropertyStatus applied. Possibly Tab-Page issue?

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


FraggleRocks posted on Monday, August 03, 2009

Has anyone noticed this?
If we apply PropertyStatus to a textbox bound to a CSLA property) (e.g. to report max length exceeded data entry error. We get a crash reported “.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Enumerator.MoveNext()
at System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e)
”.
The code works in Firefox, on a machine that only has Silverlight 3. But fails on IE8 (all machines) and also on machines that historically had Silverlight 2 installed (all browsers)

We are using CSLA 3.7.0 and Silverlight 3.

I read the article, http://www.lhotka.net/weblog/AddingDataContextChangedInSilverlight.aspx - so it sounds like changes are being made in this area.

A) Has anyone else experienced this?
B) Does anyone have a fix?
C) Is 3.7.1 due soon so we can see if that fixes it?

For your information we have a tab control, all of the textboxes on the first tab are working fine, but two textboxes on another tab consistently fail.

Please help!

RockfordLhotka replied on Monday, August 03, 2009

The blog post you refer to deals with changes I'm making for 3.7.1 (or maybe 3.8 - I might need to change the version number).

3.7.0 is 3.6.3 compiled for SL3.

In other words, the issue you are seeing has something to do with a framework change from SL2 to SL3 that must be causing an issue.

I haven't encountered this issue - can you provide any more specifics that might provide further clues? Or can you create a simple repro you can share?

FraggleRocks replied on Tuesday, August 04, 2009

I have sent a code sample via email.

Hopefully you will be able to reproduce the problem and report back.

Many thanks. Rob.

RockfordLhotka replied on Tuesday, August 04, 2009

I don't have time to create the database and so forth - but I quickly pulled
out the essence of your sample. Interestingly, I'm not able to replicate the
issue with this simple code, so clearly the issue goes beyond anything to do
with simple interactions between the TabControl and PropertyStatus control.

My page is simple, but captures the structure of your failing code:

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

xmlns:WinCtl="clr-namespace:System.Windows.Controls;assembly=System.Windows.
Controls"
xmlns:csla="clr-namespace:Csla.Silverlight;assembly=Csla"
mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">


DataChangedHandler="{StaticResource ErrorDialog}"
ManageObjectLifetime="True"
IsInitialLoadEnabled="True"
ObjectType="PropertyStatusTabs.Data,
PropertyStatusTabs"
FactoryMethod="NewData"/>

ClientData}, Path=Data}">



Mode=TwoWay}" Width="150" Margin="5"/>
RelativeTargetName="NameTextBox" Margin="5"/>





Mode=TwoWay}" Width="150" Margin="5"/>
RelativeTargetName="CityTextBox" Margin="5"/>






The only difference is that I'm not calling a WCF service to create the
object - the NewData() method runs locally and creates an empty mock object.
The "Data" object has two string properties, each with a StringRequired rule
and that's it.

If I get some more time later I'll try to work on this some more, but
there's clearly something going on in your code that triggers the issue.

If you can continue to streamline your example to the point where it
succeeds that may reveal the crux of the problem.

RockfordLhotka replied on Tuesday, August 04, 2009

Or can you provide a complete stack trace from the point of failure, that
might help.

FraggleRocks replied on Wednesday, August 05, 2009

Hi,

I am whittling my sample down. Still crashing at the moment, I will let you know if I manage to associatye the crash with one particular aspect.

My hunches were it was something to do with lazy loading, or not using latest silverlight page navigator controls. I have eliminated both of these.

My sample is now a single page displaying , with editableRoot with Editable-child.

My stack trace is as follows, I am not sure it will help much, as namespaces are system and MS.Internal!

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; InfoPath.2; .NET CLR 3.5.21022; .NET CLR 3.0.30618; .NET CLR 3.5.30729)
Timestamp: Wed, 5 Aug 2009 16:38:05 UTC


Message: Unhandled Error in Silverlight 3 Application
Code: 4004
Category: ManagedRuntimeError
Message: System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Enumerator.MoveNext()
at System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e)
at System.Windows.FrameworkElement.OnAncestorDataContextChanged(DataContextChangedEventArgs e)
at System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e)
at System.Windows.FrameworkElement.OnAncestorDataContextChanged(DataContextChangedEventArgs e)
at System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e)
at System.Windows.FrameworkElement.OnTreeParentUpdated(DependencyObject newParent, Boolean bIsNewParentAlive)
at System.Windows.DependencyObject.UpdateTreeParent(IManagedPeer oldParent, IManagedPeer newParent, Boolean bIsNewParentAlive, Boolean keepReferenceToParent)
at MS.Internal.FrameworkCallbacks.ManagedPeerTreeUpdate(IntPtr oldParentElement, IntPtr parentElement, IntPtr childElement, Byte bIsParentAlive, Byte bKeepReferenceToParent)

Line: 53
Char: 13
Code: 0
URI: http://localhost:49868/MobileSalesAssistantTestPage.html

RockfordLhotka replied on Wednesday, August 05, 2009

The problem is we don't know what collection it is talking about - an internal one, or one in CSLA or one of yours...

RockfordLhotka replied on Thursday, August 06, 2009

I believe I resolved the issue and the fix is in the 3.7.x branch in svn.

I still don't fully understand the nature of the issue, but it seems that the XAML visual tree may not be entirely stable when PropertyStatus is initially rendered. In other words, I think the visual tree is changing out from under PropertyStatus as it is being loaded - an apparently new behavior of SL3.

My resolution may or may not be a real fix. As the control loads, it now bypasses the method that attempts to resolve the relative path to the UI control to be manipulated for authz purposes. All my test apps appear to work fine with this change, but I am suspicious that there might be some edge case where it won't work properly now.

In any case, the PropertyStatus control is in the middle of a facelift for CSLA .NET 3.8 and I'm hoping to entirely eliminate this issue with the redesign (and grant more power to the XAML designer).

FraggleRocks replied on Friday, August 07, 2009

Great work Rocky,

I was suspecting that something under the hood of SL3 was giving CSLA propertystatus trouble, but analysing the problem was outside my area of expertese. Thanks for your persistance in tracking this down and adding a workaround into CSLA. I will upgrade to 3.8 when it is released.

Thanks.

RockfordLhotka replied on Friday, August 07, 2009

Just be aware that 3.8 will have breaking changes to the Silverlight and WPF
controls. I'm reworking the Silverlight controls to exploit new SL features
like element and relative binding, as well as (maybe) trigger and behavior
actions.

For parity I'm doing similar changes to the WPF side.

Adam replied on Thursday, August 13, 2009

Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4 /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin-top:0in; mso-para-margin-right:0in; mso-para-margin-bottom:10.0pt; mso-para-margin-left:0in; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:"Times New Roman"; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin;}

Hi people


I have recently had this issue and have found that if you use a direct reference instead of a relative reference it appears to work! Samples below...


This works... (direct reference)

<StackPanel DataContext="{Binding Path=Data.KitFund}">

  <TextBlock Text="Opening Balance" />

  <TextBox x:Name="OpeningBalanceTextBox" Text="{Binding Mode=TwoWay, Path=OpeningBalance}"/>

  <csla:PropertyStatus RelativeTargetName="OpeningBalanceTextBox" Property="OpeningBalance" Source="{Binding Path=Data.KitFund}"/>

</StackPanel>


This doesn’t… (relative reference)

<StackPanel DataContext="{Binding Path=Data.KitFund}">

  <TextBlock Text="Opening Balance" />

  <TextBox x:Name="OpeningBalanceTextBox" Text="{Binding Mode=TwoWay, Path=OpeningBalance}"/>

  <csla:PropertyStatus RelativeTargetName="OpeningBalanceTextBox" Property="OpeningBalance" Source="{Binding}"/>

</StackPanel>

RockfordLhotka replied on Thursday, August 13, 2009

That’s really strange, but I’m glad there’s a workaround.

 

I say it is strange, because I traced the crash down to code where it establishes the reference to the target UI control using RelativeTargetName. So it is unclear why changing the Source reference would make a difference.

Adam replied on Thursday, August 13, 2009

Please note this doesn't work for all PropertyStatues but it worked for most of mine!

RockfordLhotka replied on Thursday, August 13, 2009

Have you tried 3.7.1, as it should fix the issue.

Copyright (c) Marimer LLC