Wpf windowsformhost无法从其他dll加载usercontrol

Wpf windowsformhost无法从其他dll加载usercontrol,wpf,windowsformshost,Wpf,Windowsformshost,因此,我有一个来自另一个项目的dll,其中包含许多有用的类和控件,让我们称之为foo.dll。我正在制作一个WPF应用程序。我需要在我的应用程序中使用其中一些。我为windows窗体创建了usercontrol,并从foo.dll引用了UserControlForMe。已经展示了,一切都很好。现在我想将usercontrol插入到wpf表单中。看起来是这样的: <UserControl x:Class="FlatRectangular_Profile.UserControl1"

因此,我有一个来自另一个项目的dll,其中包含许多有用的类和控件,让我们称之为foo.dll。我正在制作一个WPF应用程序。我需要在我的应用程序中使用其中一些。我为windows窗体创建了usercontrol,并从foo.dll引用了UserControlForMe。已经展示了,一切都很好。现在我想将usercontrol插入到wpf表单中。看起来是这样的:

<UserControl x:Class="FlatRectangular_Profile.UserControl1"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             mc:Ignorable="d" 
          xmlns:uc="clr-namespace:FlatRectangular_Profile.UC"
          Height="2093" Width="717">
    <Grid Name="grid">
        <WindowsFormsHost>
            <uc:WindowsFormsProfManual ></uc:WindowsFormsProfManual>
        </WindowsFormsHost>
    </Grid>
</UserControl>
但在这里我得到一个错误,无法从foo.dll加载类型UserControlForMe。没有关于那个错误的信息。同样,UserControlForMe在WindowsFormsProfManual中加载。所有这些都在一个类库中进行。我引用了foo.dll需要的所有内容


不知道下一步该怎么办。我还尝试在usercontrol.loaded事件的代码中加载它,但也失败了,并显示了stacktrace,这将导致UserControlForMe的构造函数。

我想您必须将程序集添加到名称空间导入中,以将应用程序指向正确的方向:

xmlns:uc="clr-namespace:FlatRectangular_Profile.UC;Assembly=MyDLL"

我找到了一个解决办法,因为我不明白为什么它不起作用。如果我将UserControlForMe从foo.dll直接加载到windowsformhost,它就会工作。但如果有缓冲区dll,它在该dll中工作,但不会在其他窗口中打开。我还以编程方式将UserControlForMe添加到windowsformhost。

是否需要WindowsFormsHost?你试着把它移走了吗?我们讨论的是编译异常还是运行时异常?UserControlForMe到底是什么?我需要它,因为没有它,WPF将无法加载winforms usercontrol。它在编译时运行。UserControlForMe是一个用来画一些besier线的控件,我不想在wpf控件中重写它。在一个类库中,UC位于wpf控件旁边,我只是将UC添加到名称空间中,以避免混淆它们。两个控件都位于一个部件中。