sharppcap icon indicating copy to clipboard operation
sharppcap copied to clipboard

Matching the dependencies graph of SharpPcap and PacketDotNet

Open SebMichaud opened this issue 1 year ago • 12 comments

SharpPcap and PacketDotNet share System.Runtime.CompilerServices.Unsafe as a common dependency. But on Nugget.org, you can find they don't use the same version of this assembly. A solution is to do a binding redirect like explain here : https://nickcraver.com/blog/2020/02/11/binding-redirects/ But it would be great to avoid that by natively matching the dependencies versions.

SebMichaud avatar Apr 07 '25 21:04 SebMichaud

What error are you getting?

kayoub5 avatar Apr 08 '25 04:04 kayoub5

Hi, This one (sorry it's partially in french). When trying to use a PacketDotNet method, it wants a 6.0.0.0 version, which is a newer version compared to the one that SharpPcap wants. Using the 6.0.0.0 and a binding redirect (.config file) fix it but it's not clean. I'm using the .NET Standard versions of the assemblies on Nugget.org. Thanks

Image

SebMichaud avatar Apr 08 '25 05:04 SebMichaud

Basically it means that System.Runtime.CompilerServices.Unsafe needs to be at version 6.0.0.0 for SharpPcap and for PacketDotNet. which is not the case by default without a binding redirect.

SebMichaud avatar Apr 14 '25 14:04 SebMichaud

.NET 6 is out of support so it can't be the version being set, and System.Runtime.CompilerServices.Unsafe is not a dependency of SharpPcap to begin with in https://github.com/dotpcap/sharppcap/blob/master/SharpPcap/SharpPcap.csproj

kayoub5 avatar Apr 14 '25 15:04 kayoub5

6 is the version of the assembly not the version of the framework. System.Runtime.CompilerServices.Unsafe is a dependency of System.Memory, which itself is a dependency of SharpPcap. That's why I talked about the dependency graph in the title of the issue.

SebMichaud avatar Apr 15 '25 05:04 SebMichaud

Seeing how the example projects compile just fine, I would need a sample project to reproduce the problem.

kayoub5 avatar Apr 18 '25 19:04 kayoub5

I guess Visual Studio manages the biding redirect by itself ? LabVIEW can't do that, so I have a .config file to force it, which is a burden.

<?xml version ="1.0"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="SharpPcap Assemblies" />
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

SebMichaud avatar Apr 20 '25 08:04 SebMichaud

Ok, if this is a LabVIEW specific problem, I don't see what I can change code wise to fix it.

You are free to open a PR with a fix.

kayoub5 avatar Apr 20 '25 10:04 kayoub5

Would it be possible to publish a version of SharpPcap on nugets.org which rely on the version of system.memory which rely on the same version of System.Runtime.CompilerServices.Unsafe used by PacketDotNet ?

SebMichaud avatar Apr 20 '25 11:04 SebMichaud

Open PRs to upgrade all dependencies of sharppcap + packetnet to latest version.

Downgrading is no go.

kayoub5 avatar Apr 20 '25 14:04 kayoub5

Hi @kayoub5, is everything ok for this PR or you need something from me ?

SebMichaud avatar Apr 25 '25 10:04 SebMichaud

After another round of thinking, I think this issue can be closed, because depedencies change all the time : it would be impossible for SharpPcap to have a new version each time a depedency changes beetween SharpPcap and PacketDotNet. However, it would be good to have SharpPcap available for .Net8 in the future (that's already the case for PacketDotNet).

SebMichaud avatar May 26 '25 10:05 SebMichaud