Reporter | Frank Fella (Frank.Fella) |
---|---|
Created | Mar 5, 2012 8:13:08 PM |
Updated | Mar 5, 2012 8:13:08 PM |
Priority | Normal |
Type | Bug |
Fix versions | No Fix versions |
State | Submitted |
Assignee | Unassigned |
Subsystem | Code Analysis |
Affected versions | 6.1 |
Fixed in build | No Fixed in build |
Resharper incorrectly reports an error for the path on a binding when the following conditions are met:
When all of these conditions are met, the path will be reported as a "Parameter count mismatch" but the code executes correctly when run.
We use this pattern in quite a few places in our code and it requires that the whole team constantly sets these errors to "ignored".
I have a very small solution which demonstrates this problem easily. Here is some sample code:
// Static data class
namespace ResharperIndexerErrorDemo
{
public class Data
{
public static Data Instance { get; set; }
static Data()
{
Instance = new Data();
}
public string this[string key, string defaultValue]
{
get
{
if (key == "foo")
{
return "bar";
}
return defaultValue;
}
}
}
}
<!– Sample window xaml –>
<Window x:Class="ResharperIndexerErrorDemo.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ResharperIndexerErrorDemo"
Title="MainWindow" Height="350" Width="525">
<StackPanel>
<!– The path on these two text blocks have the resharper error "Parameter count mismatch" –>
<TextBlock Text="{Binding Source={x:Static local:Data.Instance}, Path=[foo\, unused]}"/>
<TextBlock Text="{Binding Source={x:Static local:Data.Instance}, Path=[test\, used!]}"/>
</StackPanel>
</Window>
// Sample window cs
using System.Windows;
namespace ResharperIndexerErrorDemo
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}
}
- The source of the binding is be a property on a static instance.
- The path must be a 2 parameter indexer.
- There must not be a single parameter indexer defined.
When all of these conditions are met, the path will be reported as a "Parameter count mismatch" but the code executes correctly when run.
We use this pattern in quite a few places in our code and it requires that the whole team constantly sets these errors to "ignored".
I have a very small solution which demonstrates this problem easily. Here is some sample code:
// Static data class
namespace ResharperIndexerErrorDemo
{
public class Data
{
public static Data Instance { get; set; }
static Data()
{
Instance = new Data();
}
public string this[string key, string defaultValue]
{
get
{
if (key == "foo")
{
return "bar";
}
return defaultValue;
}
}
}
}
<!– Sample window xaml –>
<Window x:Class="ResharperIndexerErrorDemo.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ResharperIndexerErrorDemo"
Title="MainWindow" Height="350" Width="525">
<StackPanel>
<!– The path on these two text blocks have the resharper error "Parameter count mismatch" –>
<TextBlock Text="{Binding Source={x:Static local:Data.Instance}, Path=[foo\, unused]}"/>
<TextBlock Text="{Binding Source={x:Static local:Data.Instance}, Path=[test\, used!]}"/>
</StackPanel>
</Window>
// Sample window cs
using System.Windows;
namespace ResharperIndexerErrorDemo
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}
}