1

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

Paul Efford
  • 261
  • 4
  • 12

2 Answers2

1

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.

Denis Kiryanov
  • 451
  • 3
  • 9
  • I've tried the release built but still threw the same exception. How can I check the PublicKeyToken part? I've never gave it in before – Paul Efford Aug 10 '23 at 06:43
  • 1
    You can follow this [instruction](https://learn.microsoft.com/en-us/dynamics-nav/how-to--determine-the-public-key-token-of-the-windows-client-control-add-in-and-.net-framework-assembly). It should be something like this command in CMD: `sn -T C:\Path\To\Your.dll`. – Denis Kiryanov Aug 10 '23 at 07:05
  • i did so but: (a) when path enclosed with quotation marks it did not "do" anything but showing the help menu, and when without, it said ´xxx.dll does not represent a strongly named assembly´ – Paul Efford Aug 10 '23 at 08:34
  • 1
    Can you find something like `` in your `.csproj` file? Try remove `PublicKeyToken` and rebuild the project. – Denis Kiryanov Aug 10 '23 at 08:50
  • no, just have "" in project.wpf file – Paul Efford Aug 10 '23 at 10:09
  • Have you installed the Microsoft Visual C++ 2010 Redistributable Package ***x86***? – Denis Kiryanov Aug 10 '23 at 10:20
  • Additionally, please make sure that there are references to `PcapDotNet.Base.dll`, `PcapDotNet.Packets.dll`, `PcapDotNet.Core.dll`, and `PcapDotNet.Core.Extensions.dll` in every project that uses PcapDotNet. – Denis Kiryanov Aug 10 '23 at 10:23
  • 1
    I updated my question with a screenshot boundaring what causes the issue... thanks for the support – Paul Efford Aug 10 '23 at 11:15
1

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>
Paul Efford
  • 261
  • 4
  • 12