views:

1054

answers:

4

I sometimes get the following exception for a custom control of mine:

XamlParseException occurred Unknown attribute Points in element SectionClickableArea [Line: 10 Position 16]

The stack trace:

{System.Windows.Markup.XamlParseException: Unknown attribute Points on element SectionClickableArea. [Line: 10 Position: 16]
   at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
   at SomeMainDialog.InitializeComponent()
   at SomeMainDialog..ctor()}

The element declaration where this happens looks like this (the event handler referenced here is defined, of course):

<l:SectionClickableArea x:Name="SomeButton" 
    Points="528,350, 508,265, 520,195, 515,190, 517,165, 530,120, 555,75, 570,61, 580,60, 600,66, 615,80, 617,335, 588,395, 550,385, 540,390, 525,393, 520,385" 
    Click="SomeButton_Click"/>

This is part of the code of SectionClickableArea:

public partial class SectionClickableArea : Button {

 public static readonly DependencyProperty PointsProperty
  = DependencyProperty.Register("Points", typeof(PointCollection), typeof(SectionClickableArea),
   new PropertyMetadata((s, e) => {
    SectionClickableArea area = (SectionClickableArea) s;
    area.areaInfo.Points = (PointCollection) e.NewValue;
    area.UpdateLabelPosition();
   }));
 public PointCollection Points {
  get { return (PointCollection) GetValue(PointsProperty); }
  set { SetValue(PointsProperty, value); }
 }

I use this control for something like a polygon-shaped button. Therefore I'm inheriting from button. I've had similar problems (E_AG_BAD_PROPERTY_VALUE on another DependencyProperty of type string, according to the line and column given, etc) with this control for weeks, but I have absolutely no idea why.


Another exception for the same control occurred this morning for another user (taken from a log and translated from German):

Type: System.InvalidCastException Message: The object of type System.Windows.Controls.ContentControl could not be converted to type [...]SectionClickableArea. at SomeOtherMainDialog.InitializeComponent()
    at SomeOtherMainDialog..ctor()

Inner exception:

Type: System.Exception Message:  An HRESULT E_FAIL error was returned when calling COM component at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
    at MS.Internal.XcpImports.SetValue(INativeCoreTypeWrapper obj, DependencyProperty property, DependencyObject doh)
    at MS.Internal.XcpImports.SetValue(INativeCoreTypeWrapper doh, DependencyProperty property, Object obj)
    at System.Windows.DependencyObject.SetObjectValueToCore(DependencyProperty dp, Object value)
    at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet, Boolean isSetByStyle, Boolean isSetByBuiltInStyle)
    at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value)
    at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
    at System.Windows.Controls.Control.set_DefaultStyleKey(Object value)
    at System.Windows.Controls.ContentControl..ctor()
    at System.Windows.CoreTypes.GetCoreWrapper(Int32 typeId)
    at MS.Internal.ManagedPeerTable.EnsureManagedPeer(IntPtr unmanagedPointer, Int32 typeIndex, Type type, Boolean preserveManagedObjectReference)
    at MS.Internal.ManagedPeerTable.EnsureManagedPeer(IntPtr unmanagedPointer, Int32 typeIndex, Type type)
    at MS.Internal.ManagedPeerTable.GetManagedPeer(IntPtr nativeObject)
    at MS.Internal.FrameworkCallbacks.SetPropertyAttribute(IntPtr nativeTarget, String attrName, String attrValue, String attachedDPOwnerNamespace, String attachedDPOwnerAssembly)

Any ideas what's wrong with the control, or what I can do to find the source of these exceptions? As I said, these problem occur only every few dozen times the control is instantiated.

A: 

I'm no XAML expert but are you missing a namespace on Points (e.g. l:Points)?

Tim Stewart
A: 

I think that we are seeing the same problem. I just get the invalidcast exception more frequently. When, through blind commenting of stuff, I can suppress the invalidcast, I do sometimes get the attribute missing error for an attribute that is, in fact, there. Have you found a solution?

BTW: the easy way to repro it is to just load the offending app and repeatedly hit F5 to refresh the page. You will get it eventually.

I have also seen an intermittent InvalidOperationException that is through from DependencyObject.get_NativeObject().

see my SO question here: http://stackoverflow.com/questions/470942/intermittent-inavlidcastexception-in-a-usercontrol-initializecomponent

See my silverlight.net bug report here: http://silverlight.net/forums/t/67732.aspx

caryden
A: 

For what it's worth, I get it too, exactly as you described.

So far I haven't found a solution (though I haven't tried too hard).

It is my intention to rewrite the custom control some other way to see whether that helps.

In the meantime I will pray that Microsoft is watching over us and bestows a bug fix.

Phil Bachmann
A: 

I've also came across this issue. I do not have a good explanation for that (seems to be XAML parse bug), but I've fixed it by adding following code to XAML:

<UserControl.Resources>
   <customNamespace:InheritedControl x:Name="dummyInstance"/>
</UserControl.Resources>
Nikolay R