为什么WPF设计无法加载调用到托管DLL库? [英] Why does the WPF designer fail to load libraries that call into unmanaged DLLs?

查看:145
本文介绍了为什么WPF设计无法加载调用到托管DLL库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Visual Studio 2008,.NET 3.5 SP1,并与下列模块的测试应用程序:

I am using Visual Studio 2008, .NET 3.5 SP1, and have a test application with the following modules:


  1. 一个C ++ DLL

  2. 一个C ++ / CLI DLL使用#1

  3. 使用#2
  4. 一个C#WPF应用程序
  1. a C++ DLL
  2. a C++/CLI DLL that uses #1
  3. a C# WPF application that uses #2

当我尝试使用从#2班作为WPF XAML资源,设计师不会让我:

When I try to use classes from #2 as resources in the WPF XAML, the designer won't let me:

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:lib1="clr-namespace:ClassLibrary1;assembly=ClassLibrary1" <- ERROR 

的错误是:。大会ClassLibrary1的未找到验证你是不是缺少程序集引用此外,验证您的项目和所有引用的程序已建成

The error is: "Assembly 'ClassLibrary1' was not found. Verify that you are not missing an assembly reference. Also, verify that your project and all referenced assemblies have been built."

但是,当我在应用程序主窗口的code-后面使用一个类从C ++ / CLI DLL,一切工作正常。 Class1的创建,并在其构造函数中调用到C ++ DLL,没有问题。

But when I use a class from the C++/CLI DLL in the code-behind of the application main window, everything works fine. Class1 is created, and in its constructor it calls into the C++ DLL, no problem.

using ClassLibrary1;

...

public partial class Window1 : Window
{
    public Window1()
    {
        InitializeComponent();

        //use in code-behind
        Class1 tmp = new Class1();
        tmp.FirstName = "foo";
        Title = tmp.FirstName;
    }
}

如果我修改C ++ / CLI组件,删除其调用到C ++ DLL和重建一切,设计师将停止抱怨,并加载C ++ / CLI装配毫无怨言。

If I modify the C++/CLI assembly, remove its call into the C++ DLL and rebuild everything, the designer stops complaining and loads the C++/CLI assembly without complaint.

我怀疑这问题有事情做与在WPF设计查找动态库。

I suspect this problem has something to do with where the WPF designer looks for dynamic libraries.

推荐答案

由于Visual Studio设计的副本程序集到一个临时位置,但不复制非托管的依赖,你可以碰到这个问题。

Because the Visual Studio designer copies your assemblies to a temporary location, but doesn't copy your unmanaged dependencies, you can run into this problem.

最简单的解决办法,虽然不是很理想,是添加包含非托管的依赖关系到 PATH 环境变量的文件夹,然后启动 devenv的.EXE PATH

The simplest solution, although not ideal, is to add a folder that contains your unmanaged dependencies to the PATH environment variable, and then start DevEnv.exe with that PATH.

您可以做到这一点无论是:

You can do this either by:


  • 使用计算机添加文件夹复制到系统环境变量 - >属性

  • 使用设置路径,然后一个批处理文件启动devenv的

这个解决方案的问题是,非托管依赖关系重建Visual Studio中往往会挂到他们还是不使用新的,所以你最终需要退出并使用设计器后重新启动Visual Studio妥善完全重建一切,这可能是一个有点疼痛。

The problem with this solution is that as the unmanaged dependencies are rebuilt Visual Studio tends to "hang onto" them or not use the new ones and so you end up needing to exit and restart Visual Studio after using the designer to properly totally rebuild everything and this can be a bit of a pain.

这篇关于为什么WPF设计无法加载调用到托管DLL库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆