6
votes

When I get a binding error in WPF, there is an error code that goes with it.

For example,

System.Windows.Data Error: 40 : BindingExpression path error: 'Product' property not found on 'object' ''ProductModel' (HashCode=57788087)'. BindingExpression:Path=Product; DataItem='ProductModel' (HashCode=57788087); target element is 'TextBox' (Name=''); target property is 'Text' (type 'String')

or

System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.ItemsControl', AncestorLevel='1''. BindingExpression:Path=HorizontalContentAlignment; DataItem=null; target element is 'MenuItem' (Name=''); target property is 'HorizontalContentAlignment' (type 'HorizontalAlignment')

What do these error codes represent, and where can I find a list of them?

1
I don't think there are any official documentation for the list of WPF errors (here binding errors). But if you want to troubleshoot then there is a good article on how to debug. Troubleshooting WPF (Debugging WPF)Anit Lacoul

1 Answers

8
votes

I don't think you'll find an official source documentation anywhere, these appear to be messages and codes internal to WPF assemblies.

This won't be the single place to find all the possible errors but if you look at the source, you could look at the MS.Internal.TraceData class and you'll find your error messages and codes there. It looks like it was refactored since this answer was posted but you can find these in the generated AvTraceMessages.cs file.

For instance, TraceData.ClrReplaceItem() corresponds to error 40 and TraceData.NoSource() corresponds to error 4.

Fortunately we now have access to the resource file that was used to generate these messages which you can find here. It looks like the error codes might correspond to the index within this file.