PcapDotNet 在 Visual Studio 中出现 System.IO.FileNotFoundException。

huangapple go评论114阅读模式
英文:

PcapDotNet System.IO.FileNotFoundException in Visual Studio

问题

我有一个C#解决方案(.Net 7.0),最近我添加了PcapDotNet库。现在我运行项目,但一直出现以下错误:

System.IO.FileNotFoundException: '无法加载文件或程序集'PcapDotNet.Core,版本=0.10.0.20632,Culture=neutral,PublicKeyToken=4b6f3e583145a652'。系统找不到指定的文件。'

我尝试降级目标框架,但仍然无法工作。我知道这么说有点奇怪,但它以前已经工作过了。项目没有错误,显然我需要这个库来处理网络数据包。

有关解决此问题的提示吗?
提前感谢。

编辑:

当我使用以下代码行时出现问题:if (communicator.ReceivePacket(out Packet packet) == PacketCommunicatorReceiveResult.Ok),我收到警告:类型'Packet'是在一个未引用的程序集中定义的。您必须引用程序集'PcapDotNet.Packets,版本=0.10.0.20603,Culture=neutral,PublicKeyToken=...'。被提到的Packet类来自using PcapDotNet.Core

英文:

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

答案1

得分: 1

请确保您的项目是以“Release”模式构建的,而不是“Debug”模式。不要忘记检查此依赖项是否真的存在,以及是否具有您特定的“PublicKeyToken”和“Version”。

另外,请参阅在您的程序中使用Pcap.Net指南和常见问题解答(问题#6)。

希望这有所帮助。

英文:

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.

答案2

得分: 1

我成功解决了它,通过将库降级到 PcapDotNet (0.10.1),在 Visual Studio 上点击项目名称,然后删除那里的代码,然后粘贴以下代码:

<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>
英文:

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:

&lt;Project Sdk=&quot;Microsoft.NET.Sdk&quot;&gt;

  &lt;PropertyGroup&gt;
    &lt;OutputType&gt;WinExe&lt;/OutputType&gt;
    &lt;TargetFramework&gt;net7.0-windows&lt;/TargetFramework&gt;
    &lt;Nullable&gt;enable&lt;/Nullable&gt;
    &lt;UseWPF&gt;true&lt;/UseWPF&gt;
  &lt;/PropertyGroup&gt;

  &lt;ItemGroup&gt;
    &lt;PackageReference Include=&quot;PcapDotNet&quot; Version=&quot;0.10.1&quot; /&gt;
  &lt;/ItemGroup&gt;

&lt;/Project&gt;

huangapple
  • 本文由 发表于 2023年8月10日 14:13:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/76873038.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定