ReSharper validation rules around WPF dictionaries slightly wrong

I noticed that one of our functions is getting flagged as an error by ReSharper even though it compiles and runs fine. Here's a simplest-case repro:

  1. VS2010 new WPF app project
  2. Right-click the project and add new Resource Dictionary
  3. Go into the xaml for Dictionary1 and add this to the ResourceDictionary tag:

          x:Class="Dictionary1"

  4. Go to MainWindow.xaml.cs and change it like this:

Snippet
using System.Windows;
using System.Windows.Markup;

namespace WpfApplication11
{
     class Test
     {
          public static void Foo<T>()
               where T : IComponentConnector, new()
          {
               var d = new Dictionary1();
               d.InitializeComponent();
          }
     }

     public partial class MainWindow
     {
          public MainWindow()
          {
               InitializeComponent();

               Test.Foo<Dictionary1>();
          }
     }
}


Here are the results:

shot5.png

What happens is that ReSharper flags the call to Foo<Dictionary1> as invalid because Dictionary1 doesn't implement IComponentConnector in the code. This is true until compile time, where the Xaml processor inserts an IComponentConnector implementation into the Dictionary1 type.

If the above is set to Test.Foo<MainWindow>() it has the same problem. You can even put "IComponentConnector c = this" and it will compile fine but Reflector will flag it as an error.

So it seems ReSharper needs to assume that certain types run through a Xaml processor will end up with IComponentConnector implementations. I don't know what the rules are around that; I hope they are documented.

This is in 5.1.1720.15.
1 comment
Comment actions Permalink

Thanks. Fixed

0

Please sign in to leave a comment.