将引用C ++ / CLI包装器的UserControl添加到表单的非托管dll时出现问题

时间:2022-09-01 20:51:50

My UserControl references a C++/CLI wrapper to an unmanaged C++ dll. When I try to add the UserControl to a form, I get a Visual Studio error, which says "Failed to create component 'userControl'", giving a System.IO.FileNotFoundException as the cause.

我的UserControl将C ++ / CLI包装器引用到非托管C ++ dll。当我尝试将UserControl添加到表单时,我收到一个Visual Studio错误,其中显示“无法创建组件'userControl'”,并将System.IO.FileNotFoundException作为原因。

From what I've been able to determine, the problem stems from visual studio not copying the C++/CLI wrapper assembly's unmanaged dependencies. If I put the unmanaged dependencies on the system PATH, everything works fine.

从我能够确定的,问题源于visual studio不复制C ++ / CLI包装程序集的非托管依赖项。如果我将非托管依赖项放在系统PATH上,一切正常。

Is there a better way of doing this?

有更好的方法吗?

2 个解决方案

#1


The easiest thing to do would be to include the actual .dll in your project, mark its build action as "Content", then set the Copy to Output Directory to "Always". This should get the .dll into your output directory so that your application can run, and just including the file in the project should put it in the project directory so that the designer can find it.

最简单的方法是在项目中包含实际的.dll,将其构建操作标记为“Content”,然后将Copy to Output Directory设置为“Always”。这应该将.dll放到您的输出目录中,以便您的应用程序可以运行,只需在项目中包含该文件就应该将它放在项目目录中,以便设计人员可以找到它。

Be sure that your setup project includes a project output for the Content files from that project as well.

确保您的安装项目还包含该项目的内容文件的项目输出。

Edit

If those don't work, you can also edit the reference paths of the project itself (in the project properties), though I am not certain that this will affect the designer. If that doesn't then your only real option is to have the .dll in one of the system path directories.

如果这些不起作用,您也可以编辑项目本身的参考路径(在项目属性中),但我不确定这会影响设计者。如果没有,那么你唯一真正的选择是将.dll放在一个系统路径目录中。

#2


Old thread, but submitting my solution since I just encountered the issue and found this question during the process.

旧线程,但提交我的解决方案,因为我刚遇到问题,并在此过程中发现此问题。

Basically I just made the native DLLs to be delay loaded in my wrapper C++/CLI library. Since the C++/CLI part of the wrapper contains the interface specs used by Visual Studio and the framework, the native DLL is never needed or loaded. I answered it with a little more details in this question too: https://*.com/a/15481687/34440

基本上我只是在我的包装器C ++ / CLI库中使本机DLL延迟加载。由于包装器的C ++ / CLI部分包含Visual Studio和框架使用的接口规范,因此永远不需要或加载本机DLL。我在这个问题中回答了一些细节:https://*.com/a/15481687/34440

#1


The easiest thing to do would be to include the actual .dll in your project, mark its build action as "Content", then set the Copy to Output Directory to "Always". This should get the .dll into your output directory so that your application can run, and just including the file in the project should put it in the project directory so that the designer can find it.

最简单的方法是在项目中包含实际的.dll,将其构建操作标记为“Content”,然后将Copy to Output Directory设置为“Always”。这应该将.dll放到您的输出目录中,以便您的应用程序可以运行,只需在项目中包含该文件就应该将它放在项目目录中,以便设计人员可以找到它。

Be sure that your setup project includes a project output for the Content files from that project as well.

确保您的安装项目还包含该项目的内容文件的项目输出。

Edit

If those don't work, you can also edit the reference paths of the project itself (in the project properties), though I am not certain that this will affect the designer. If that doesn't then your only real option is to have the .dll in one of the system path directories.

如果这些不起作用,您也可以编辑项目本身的参考路径(在项目属性中),但我不确定这会影响设计者。如果没有,那么你唯一真正的选择是将.dll放在一个系统路径目录中。

#2


Old thread, but submitting my solution since I just encountered the issue and found this question during the process.

旧线程,但提交我的解决方案,因为我刚遇到问题,并在此过程中发现此问题。

Basically I just made the native DLLs to be delay loaded in my wrapper C++/CLI library. Since the C++/CLI part of the wrapper contains the interface specs used by Visual Studio and the framework, the native DLL is never needed or loaded. I answered it with a little more details in this question too: https://*.com/a/15481687/34440

基本上我只是在我的包装器C ++ / CLI库中使本机DLL延迟加载。由于包装器的C ++ / CLI部分包含Visual Studio和框架使用的接口规范,因此永远不需要或加载本机DLL。我在这个问题中回答了一些细节:https://*.com/a/15481687/34440