Skip to main content
Home Forums Silverlight Programming Report a Silverlight Bug Incorrect message in exception - NotifyCollectionChangedArgs ctor
4 replies. Latest Post by shacktoms on December 22, 2008.
(0)
shacktoms
Member
185 points
149 Posts
10-01-2008 2:14 PM |
I called
e = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, null, this[0], 0)
"Constructor supports only the 'Remove' action."
I think it should be
"Constructor supports only the 'Replace' action."
Jonathan...
All-Star
24626 points
2,418 Posts
10-02-2008 11:11 PM |
Hi Shacktoms,
To make our investigation easier to perform, would you please provide a tiny repro here? Thanks for your understanding.
Best regards,
Jonathan
10-04-2008 5:22 AM |
I already provided code that would reproduce the bad error message, clearly that code assumes you are implementing a collection object and are removing the first element from that collection. But if you want something smaller, the bad error message can be reproduced very easiily, even without going to the trouble of implementing INotifyCollectionChanged in a class.
How about this? New Silverlight project is named TestNotifyCollection. Page.xaml looks like this...
<UserControl x:Class="TestNotifyCollection.Page" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:TestNotifyCollection" Width="400" Height="300"> <Grid x:Name="LayoutRoot" Background="White"> <local:Test/> </Grid> </UserControl>
Page.xaml.cs looks like this
using System; using System.Collections.Specialized; using System.Windows.Controls; namespace TestNotifyCollection { public class Test : ContentControl { public Test() { try { var e = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, null, this, 0); } catch (Exception e) { Content = e.Message; } } } public partial class Page : UserControl { public Page() { InitializeComponent(); } } }
Note that in Blend, the message is different, I guess that can be taken as a failure of Blend to simulate the actual application. But if you actually build and run the application, even from Blend, or view it in Visual Studio 2008, you will see the incorrect error text in Siliverlight.
Obviously this is a really minor bug. My code was broken, but I had noticed that the error message was incorrect in its descriptive text.
12-17-2008 10:25 PM |
Sorry that I missed your reply. If your problem persists there, please post another thread and let me know. Thanks.
12-22-2008 10:47 AM |
I rebuilt and reran the test application and the bug is still there, the error message still says the constructor only supports the "Remove" operation, although it actually only supports the "Replace" operation. Looks like a cut and paste error in the Silverlight code.
Which reply did you miss? The reply to your private message? That looked like this...I have looked at the reflection code with the Red Gate reflector and I think the bug is clearly there. What I see in the code for the constructor is this...
1 public NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction action, object newItem, object oldItem, int index) 2 { 3 this._newStartingIndex = -1; 4 this._oldStartingIndex = -1; 5 if (action != NotifyCollectionChangedAction.Replace) 6 { 7 StringBuilder builder = new StringBuilder(); 8 builder.AppendFormat(Resx.GetString("NotifyCollectionChangedEventArgs_UnSupportedConstructorAction"), new object[] { NotifyCollectionChangedAction.Remove }); 9 throw new NotSupportedException(builder.ToString()); 10 } 11 this._action = action; 12 this._newItems = new object[] { newItem }; 13 this._oldItems = new object[] { oldItem }; 14 this._newStartingIndex = index; 15 } 16