
{"id":2427,"date":"2017-08-28T17:39:58","date_gmt":"2017-08-28T21:39:58","guid":{"rendered":"http:\/\/www.ikriv.com\/blog\/?p=2427"},"modified":"2017-08-28T17:39:58","modified_gmt":"2017-08-28T21:39:58","slug":"doubleupdown-targettype-does-not-match-type-of-element-doubleupdown","status":"publish","type":"post","link":"https:\/\/ikriv.com\/blog\/?p=2427","title":{"rendered":"&#8216;DoubleUpDown&#8217; TargetType does not match type of element &#8216;DoubleUpDown&#8217;"},"content":{"rendered":"<p>Our WPF started to hang when opening certain window, and debugging revealed an <code>InvalidOperationException<\/code> with this mysterious message. After some digging I found that we had code along the lines of<\/p>\n<pre>...\r\nxmlns:xctk=\"http:\/\/schemas.xceed.com\/wpf\/xaml\/toolkit\"\r\n...\r\n<span style=\"font-size: 20px;\">&lt;Style TargetType=\"{x:Type xctk:DoubleUpDown}\" x:Key=\"bla\" ... \/&gt;\r\n...\r\n&lt;xctk:DoubleUpDown Style=\"{StaticResource bla}\" ... \/&gt;<\/span><\/pre>\n<p>Somehow it happened, that the control was coming from one assembly: <code>Xceed.Wpf.Toolkit.DoubleUpDown, Xceed.Wpf.Toolkit, Version=1.9.0.0<\/code>, and the style was targeting a type in another assembly: <code>Xceed.Wpf.Toolkit.DoubleUpDown, WPFToolkit.Extended, Version=1.8.0.0<\/code>.<\/p>\n<p>These two assemblies are in fact two versions of Xceed WPF toolkit: they contain the same classes assigned to the same XML namespace. Our mistake was to reference both the old and the new assembly, which led to confusion.<\/p>\n<p>When we say <code>xctk:DoubleUpDown<\/code>, it may map to either of those assemblies, and I am not sure how exactly WPF makes the choice, but apparently the choice may be inconsistent and thus lead to cryptic error messages.<\/p>\n<p>There are several takeaways\/anti-patterns that played a dirty trick on us in this case:<\/p>\n<ul>\n<li>Xceed should have changed XML namespace, and also the CLR namespace when they changed the assembly name. Creating two different assemblies with the same classes is asking for trouble.<\/li>\n<li>WPF should have included full class information somewhere in the error message. Don&#8217;t assume that class name or even fully qualified class name uniquely identifies the class.<\/li>\n<li>Painting errors should not be fatal. The above XAML error triggered an exception during &#8216;measure&#8217; phase of each re-paint cycle, effectively hanging the application. There should have been a better way to recover from it, e.g. show an empty window or something.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Our WPF started to hang when opening certain window, and debugging revealed an InvalidOperationException with this mysterious message. After some digging I found that we had code along the lines <a href=\"https:\/\/ikriv.com\/blog\/?p=2427\" class=\"more-link\">[&hellip;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"Layout":"","footnotes":""},"categories":[3,12],"tags":[],"class_list":["entry","author-ikriv","post-2427","post","type-post","status-publish","format-standard","category-dotnet","category-wpf"],"_links":{"self":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2427","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2427"}],"version-history":[{"count":1,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2427\/revisions"}],"predecessor-version":[{"id":2428,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2427\/revisions\/2428"}],"wp:attachment":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2427"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2427"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2427"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}