简体   繁体   中英

Two IMultiValueConverters with identical code, but different names - only one works

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();
    }
}

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM