线程中的 system.windows.forms.dll 中第一次出现 NullReferenceException 类型的异常
我正在用 vc++ 编写一个 dll 来阻止端口(如 tcp 嗅探器)。在本地计算机中阻止 udp 端口时,它工作正常。当我从我的系统中获取远程计算机时,它会引发异常,
"system.NullReferenceException'occurred in system.windows.forms.dll"
我将 dll 合并到了 c# 应用程序中。请提供您的建议
am doing a dll in vc++ for blocking ports(like tcp sniffer).while blocking udp port in local machine its works fine.while am taking remote computer from my my system its raises on exception
"system.NullReferenceException'occurred in system.windows.forms.dll"
i incorporated the dll in c# application.please give your suggestion
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于信息非常有限,我能想到的最可能的原因是:
您的 C# 应用程序正在尝试创建 C++ dll 类的实例,并且很可能失败,导致 NULL 指针。稍后通过该实例调用方法会导致此异常。
要解决此问题,您应该首先检查实例是否创建成功。
With very limited information, The most probable cause that I can think of is:
Your C# application is trying to create an instance of the C++ dll's class and most probably that fails resulting in a NULL pointer. The later call of a method through that instance is resulting in this exception.
To resolve this, you should check first whether instance was created successfully or not.
遗憾的是您没有收集和分享这些信息。不用担心。这是最容易检测和修复的情况之一。它只是意味着某些引用类型的某些成员/变量通过使用其实例(非静态)成员的 and 来取消引用,这要求该成员/变量为非空,但实际上它看起来为空。只需在调试器下执行它,它就会在抛出异常的地方停止执行。在该行上放置一个断点,重新启动应用程序并再次到达这一点。评估下一行中涉及的所有引用,看看哪一个为空,而它需要不为空。弄清楚这一点后,修复代码:要么确保成员/变量正确初始化为非空引用,要么检查它是否为空,如果为空,则执行其他操作。
Too bad you did not collect and share this information. Not to worry. This is one of the very easiest cases to detect and fix. It simply means that some member/variable of some reference type is dereferenced by using and of its instance (non-static) members, which requires this member/variable to be non-null, but in fact it appears to be null. Simply execute it under debugger, it will stop the execution where the exception is thrown. Put a break point on that line, restart the application and come to this point again. Evaluate all references involved in next line and see which one is null while it needs to be not null. After you figure this out, fix the code: either make sure the member/variable is properly initialized to a non-null reference, or check it for null and, in case of null, do something else.