How to add types from external assembly to toolbox control? (WPF)

Posted by Louis Rhys on Stack Overflow See other posts from Stack Overflow or by Louis Rhys
Published on 2011-01-04T14:58:29Z Indexed on 2011/01/05 3:53 UTC
Read the original article Hit count: 123

Filed under:
|
|
|
|

I am trying to do something like this in my WPF application:

    ToolboxControl ctrl = new ToolboxControl();
    Assembly assembly = Assembly.LoadFile(file);
    var category = new ToolboxCategory(assembly.GetName().Name);
    foreach (Type t in assembly.GetTypes())
    {
        var wrapper = new ToolboxItemWrapper(t, t.Name);
        category.Add(wrapper);
    }
    ctrl.Categories.Add(category);

i.e. adding ToolboxItemWrappers for each type found in an assembly. However the last line throws the following exception (see image)

http://img41.imageshack.us/img41/2261/7xvqv.png

All dependencies of the external assembly are also referenced in the main (WPF) application. So what's wrong here and how to fix it?

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET