在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了。