将引用 C++CLI 包装器到非托管 dll 的 UserControl 添加到表单时出现问题
我的 UserControl 将 C++/CLI 包装器引用到非托管 C++ dll。 当我尝试将 UserControl 添加到表单时,出现 Visual Studio 错误,显示“无法创建组件‘userControl’”,并给出 System.IO.FileNotFoundException 作为原因。
据我所知,问题源于 Visual Studio 没有复制 C++/CLI 包装器程序集的非托管依赖项。 如果我将非托管依赖项放在系统路径上,一切都会正常工作。
有更好的方法吗?
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.
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.
Is there a better way of doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最简单的方法是将实际的 .dll 包含在项目中,将其构建操作标记为“内容”,然后将“复制到输出目录”设置为“始终”。 这应该将 .dll 放入您的输出目录中,以便您的应用程序可以运行,并且只需将文件包含在项目中就可以将其放入项目目录中,以便设计人员可以找到它。
确保您的安装项目也包含该项目的内容文件的项目输出。
编辑
如果这些不起作用,您还可以编辑项目本身的参考路径(在项目属性中),尽管我不确定这是否会影响设计器。 如果没有,那么您唯一真正的选择是将 .dll 放在系统路径目录之一中。
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.
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 延迟加载到我的包装器 C++/CLI 库中。 由于包装器的 C++/CLI 部分包含 Visual Studio 和框架使用的接口规范,因此永远不需要或加载本机 DLL。 我在这个问题中也回答了更多细节:
https://stackoverflow.com/a/15481687/34440
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://stackoverflow.com/a/15481687/34440