System.DllNotFoundException: Unable to load DLL 'wpcap' or one of its dependencies: 找不到指定的模块。 (0x8007007E)

在NuGet安装了SharpPcap5.3.0,并使用SharpPcap5.3.0编写了程序,在本机运行是没问题,但部署到另一部电脑就会报以下错误:

2020-10-22 16:37:17,273 [1] ERROR LogInfo - System.DllNotFoundException: Unable to load DLL 'wpcap' or one of its dependencies: 找不到指定的模块。 (0x8007007E)
   at SharpPcap.LibPcap.Windows.pcap_findalldevs(IntPtr& alldevs, StringBuilder errbuf)
   at SharpPcap.LibPcap.LibPcapSafeNativeMethods.pcap_findalldevs(IntPtr& alldevs, StringBuilder errbuf)
   at SharpPcap.LibPcap.PcapInterface.GetAllPcapInterfaces()
   at SharpPcap.Npcap.NpcapDeviceList.Refresh()
   at SharpPcap.Npcap.NpcapDeviceList..ctor()
   at SharpPcap.Npcap.NpcapDeviceList.get_Instance()
   at SharpPcap.CaptureDeviceList..ctor()
   at SharpPcap.CaptureDeviceList.get_Instance()

查到是缺少了c:\Windows\System32\Npcap 里的wpcap.dll,而且安装WireShark软件就会有这个dll。我本机早就安装了WireShark所以一直没问题,其它没安装的就会报上边的错。

 

那么使用NuGet安装SharpPcap5.3.0编程的,居然遇到坑了?不可能吧。于是将c:\Windows\System32\Npcap里的wpcap.dll和Packet.dll,复制到工程exe同级的目录下,再次运行就OK了。

 

参考:https://stackoverflow.com/questions/58010149/unable-to-load-dll-wpcap-dll-the-specified-module-is-not-found

posted @ 2020-10-22 17:19  努力吧兄Dei  阅读(3364)  评论(0编辑  收藏  举报