c# – Problem with custom type converter in VSX package – Education Career Blog

I have the following question. I have MSVS solution with three projects in it.

  • first project is VSX project witch shows form with property grid in it.
  • second is typical C# library project with custom type converter class BooleanYesNoConverter inherited from BooleanConverter. This converter is used to show Yes/No in property grid instead of True/False.
  • third project is also C# library project which contains public class with one public property which has attribute TypeConverter(typeof(BooleanYesNoConverter))

There are references to second project from first and third.

When when we start first project in debug mode (in VS Experimental hive) and click on menu, plugin loads assembly generated from third project (with help of Assembly.LoadFrom) and instantiates our class (with one public boolean property). Then it pass this instance to propertyGrid.SelectedObject property. Property grid displays public property but instead Yes/No it shows True/False on the right.

I have put breakpoints in coverter’s methods (and constructor) but it seems like we didn’t go there. Instead of custom type converter, standard is used.

It is more interesting, that if I place BooleanYesNoConverter class in the third project (so it will be n one assembly with my class) property grid shows correct Yes/No variants.

Thank you for your help in advance!

,

Surfing the Internet I have found that not just I came across such kind of problem. I have found similar questions in the following place:

http://social.msdn.microsoft.com/Forums/en/vsx/thread/a04b45d2-1d0a-4cfc-a0f0-1d458b2d6e26

(one more link you can find in my comment)

And I have found suitable (for me) decision: I wrote assembly resolver. In other words, I add following code in my plugin’s initialization method:

    AppDomain.CurrentDomain.AssemblyResolve +=
    new ResolveEventHandler(LoadAssembly);

and this method to plugin’s class:

    private Assembly LoadAssembly(object sender, ResolveEventArgs e)
    {
        int commaIndex = e.Name.IndexOf(',');
        string fileName = e.Name.Substring(0, commaIndex) + ".dll";
        Assembly assembly = Assembly.LoadFrom(fileName);
        return assembly;
    }

Now it works fine.

Leave a Comment