0

I'm having a weird WPF issue. I have two IMultiValueConverter definitions in an assembly that is referenced by my WPF project. Their code is identical, but their names are different. I have cleaned and rebuilt the assemblies multiple times, but for some reason only one of the Value converters works, while the other one gives a 'does not exist in the clr namespace' xaml error.

Note: I know for a fact that the file is in the correct namespace and assembly that the project is referencing, because I reflected the dll directly out of the WPF project's bin folder.

Is there any explanation for this phenomenon?

//// this works
public class IndexConverter : IMultiValueConverter
{
    public virtual object Convert(
        object[] values, Type targetType,
        object parameter, System.Globalization.CultureInfo culture)
    {
        var element = values[0] as Object;
        var sequence = values[1] as IEnumerable;
        return sequence.Cast<Object>().ToList().FindIndex(c => c.Equals(element)).ToString();
    }

    public virtual object[] ConvertBack(
        object value, Type[] targetTypes,
        object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}



////  this gives me xaml errors
public class IndexConverterCopy : IMultiValueConverter
{
    public virtual object Convert(
        object[] values, Type targetType,
        object parameter, System.Globalization.CultureInfo culture)
    {
        var element = values[0] as Object;
        var sequence = values[1] as IEnumerable;
        return sequence.Cast<Object>().ToList().FindIndex(c => c.Equals(element)).ToString();
    }

    public virtual object[] ConvertBack(
        object value, Type[] targetTypes,
        object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}
smartcaveman
  • 41,281
  • 29
  • 127
  • 212
  • Can you show some code? – Rohit Vats Mar 03 '13 at 10:28
  • Remove the reference of this second Converter from xaml and then build the project where this converter is available and then add the xaml removed code back and then build. – yo chauhan Mar 03 '13 at 10:36
  • Few quick questions -Namespace is same? And xaml where you are referring these converters(can you post that code as well)? Any reasons for making method virtual (not related though)? – Rohit Vats Mar 03 '13 at 10:38
  • I just copy pasted both work fine?? VS2012 has some pretty anoying bugs in the xaml editor, try opening your project in another VS instance and see if it compiles there – sa_ddam213 Mar 03 '13 at 10:38
  • @ethicallogics - no dice – smartcaveman Mar 03 '13 at 10:41
  • @sa_ddam213 - trying now..hold on.. – smartcaveman Mar 03 '13 at 10:42
  • @sa_ddam213 - That worked. Any idea why? – smartcaveman Mar 03 '13 at 10:43
  • @smartcaveman, not sure, I have real troubles with the new VS, stuff like this happens a lot, the worst one is `ctrl+z` stops working and you have to restart VS to get it back, which can be painfull when you changed your whole layout then wanted to revert. Hope the next service pack fixes these bugs. – sa_ddam213 Mar 03 '13 at 10:46
  • @sa_ddam213 - if you add your comment as an answer i will accept – smartcaveman Mar 03 '13 at 11:03

1 Answers1

1

There is some strange bugs in the new VS2012 which seems like some kind of caching issue.

The only solution is to restart VisualStudio.

So far I have found 3 bugs like this

  1. change your xaml layout, it changes in designer view, hit F5 to build, application does not show new changes, needs VS restart
  2. All your undo data dissapears and ctrl+z no longer works, needs VS restart
  3. Designer will not show anything and displays IndexOutOfRange exception, needs VS restart

This issue sounds like its coming from the same area where the xaml and cs somehow become out of sync, so a Restart of VS may be the only fix for your issue aswell (Bring on SP1)

sa_ddam213
  • 42,848
  • 7
  • 101
  • 110