PcapDotNet System.IO.FileNotFoundException in Visual Studio

142 Views Asked by At

I have a C# solution (.Net 7.0) where I recently added the PcapDotNet libraries. Now I run the project and I keep getting this error:

System.IO.FileNotFoundException: 'Could not load file or assembly 'PcapDotNet.Core, Version=0.10.0.20632, Culture=neutral, PublicKeyToken=4b6f3e583145a652'. The system cannot find the file specified.'

I tried downgrading the target framework but still doesn't work.I know it's weird to say this, but it already worked "before". The project has no errors and I obviously need this library to work with network packages.

Any hints to solving this? Thanks in advance.

EDIT:

The issue arrises when I use the line if (communicator.ReceivePacket(out Packet packet) == PacketCommunicatorReceiveResult.Ok) where I am warned with The type 'Packet' is defined in an assembly that is not referenced. You must a reference to assembly 'PcapDotNet.Packets, Version=0.10.0.20603, Culture=neutral, PublicKeyToken=...'

The mentioned Packet class comes from using PcapDotNet.Core

2

There are 2 best solutions below

0
Paul Efford On BEST ANSWER

I managed to solve it by downgrading the library to PcapDotNet (0.10.1), clicking on the project name on Visual Studio, and then deleting the code there and pasting instead this one:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net7.0-windows</TargetFramework>
    <Nullable>enable</Nullable>
    <UseWPF>true</UseWPF>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="PcapDotNet" Version="0.10.1" />
  </ItemGroup>

</Project>
8
Denis Kiryanov On

Please make sure your project was built in Release mode and not Debug. Do not forget to check if this dependency really exists, with your particular PublicKeyToken and Version.

Also, please see the Using Pcap.Net in your programs guide and the FAQ (question #6).

Hope this helps.