在 C++/CLI 中添加对库的引用的正确方法是什么?
我正在用 C++/CLI 编写一个库,其中一个函数返回 System::Drawing::Color 对象。我添加了 System.Drawing 作为项目参考。有用。
然后,我创建了一个测试应用程序来链接到该库,并添加我创建的库作为参考。一切都链接得很好,但后来我尝试运行应用程序,却收到错误“单元测试适配器抛出异常:无法加载一种或多种请求的类型。检索 LoaderExceptions 属性以获取更多信息..”(我不知道)不知道如何访问此 LoaderException 属性)。
通过在测试项目中向 System.Drawing 添加第二个引用解决了这个问题,但这看起来很俗气。我的库的使用者不必了解该库的依赖关系。为什么添加对我的库的引用不知道对 System.Drawing 的依赖性?我觉得我做错了什么。
谢谢您的建议。
I am writing a lib in C++/CLI, and one of the functions is returning a System::Drawing::Color object. I added System.Drawing as a project reference. It works.
I then created a test application to link to this lib and added my created lib as a reference. Everything linked fine, but then I tried to the run the application and I had the error "Unit Test Adapter threw exception: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.." (I don't know how to access this LoaderException property).
This problem was fixed by adding a second reference, in the test project, to System.Drawing, but it seems cheesy. Consumers of my library should not have to know about the dependencies on the lib. Why didn't adding a reference to my lib know about the dependancy to System.Drawing? I feel I am doing something wrong.
Thank you for your advice.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我用更多与语言无关的设计术语重新表述了这个问题:此处。普遍的共识似乎是消除对其他库的依赖,那么这个问题就不会存在。
I rephrased the question in more language agnostic design terms: here. The general consensus seems to be to remove dependencies on other libraries, and then this problem won't exist.