如何从外部集添加类型工具箱中的控制? (WPF)工具箱、类型、WPF

2023-09-07 08:43:50 作者:花無聲淚無痕

我试图做这样的事情在我的WPF应用程序:

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

即。加入ToolboxItemWrappers在装配中每种类型。然而,最后一行抛出以下异常(见图片)

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

外部组件的所有依存关系也可参考在main(WPF)应用程序。那么,什么是错在这里,如何解决这个问题?

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

推荐答案

是文件中的CustomLibrary组装?如果不是,钩此事件​​AppDomain.CurrentDomain.AssemblyResolve在你的应用程序,并加载任何其他组件的组合件的文件路径参考。如果CustomLibrary或其他DLL不在GAC这是必需的。

Is the CustomLibrary assembly in the file? If not, hook to this event AppDomain.CurrentDomain.AssemblyResolve in you app, and load any other assemblies that the assembly at the filePath references to. It is required if CustomLibrary or other dlls are not in GAC.