运行 C++ 通过 NUnit 编写代码
我尝试使用 NUnit 来测试已经连接到 C++ 代码的 C# 代码(没有 NUnit,应用程序可以完美运行)。
在我的测试中,我通过 AppDomain.CurrentDomain.ExecuteAssembly(..) 运行 main 函数,但是当 C# 代码尝试与 C++“通信”时,它会引发异常并且测试崩溃。 例外是 System.Reflection.TargetInitationException 如果有人知道为什么会发生它将会非常非常有帮助......谢谢,Naama
I have tried to use NUnit to test C# code the is already connected to C++ code (without the NUnit the application work perfectly).
In my test I run the main function through AppDomain.CurrentDomain.ExecuteAssembly(..), However when the C# code tries to "communicate" with the C++ it throws an exception and the test crashes. The exception is System.Reflection.TargetInvocationException if anyone has and idea why its happen it will be very very helpful... Thanks, Naama
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的怀疑是正确的,它是在构造函数期间通过的,c# 中的构造函数正在尝试创建一个对象(它已经被包装并且在应用程序正常运行时完美工作),该对象是用 c++ 编写的,并且在 c++ 的构造函数中编写的对象抛出异常。
然而,该应用程序非常复杂,但如果需要澄清,我将编写一个代表真实应用程序的演示应用程序。
Your suspicions are correct it is being through during the constructor, the constructor in c# is trying to create an object (it is already wrapped and work perfect when the application is running normally) that is written in c++ and in c++ in the constructor of the object the exception is thrown.
However the application is very complex but if it necessary for clarification I will write a demo application that symbol the real one.
您的 C++ 代码中的类构造函数中可能会引发异常。 检查以确保您正确处理异常,并且向构造函数提供正确的信息,以便不会引发异常。
It is likely that an exception is being thrown in your C++ code, in the constructor of the class. Check to make sure you're handling exceptions properly and that you're giving the proper information to the constructor so exceptions aren't thrown.