alanmcgovern / monotorrent

The official repository for MonoTorrent, a bittorrent library for .NET
https://github.com/alanmcgovern/monotorrent
MIT License
1.15k stars 397 forks source link

Missing dependency - System.Runtime.CompilerServices.Unsafe #687

Closed foxi69 closed 2 months ago

foxi69 commented 2 months ago

Since I updated from version 2.0.7 to 3.0.2, this error #649 has since been solved, but another similar one has appeared before, if I can see correctly, it has been fixed #582, you could not add a similar solution to "System.Runtime.CompilerServices .Unsafe" dependency?

Exception type : System.BadImageFormatException
Message : Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. Reference assemblies should not be loaded for execution.  They can only be loaded in the Reflection-only loader context. (Exception from HRESULT: 0x80131058)
StackTrace :    at System.Span`1..ctor(T[] array)
   at MonoTorrent.BEncoding.BEncodedValue.Encode() in C:\Projects\monotorrent\src\MonoTorrent.BEncoding\MonoTorrent.BEncoding\BEncodedValue.cs:line 50
   at MonoTorrent.BEncoding.BEncodedValue.Clone[T](T value) in C:\Projects\monotorrent\src\MonoTorrent.BEncoding\MonoTorrent.BEncoding\BEncodedValue.cs:line 65
   at MonoTorrent.EditableTorrent..ctor(BEncodedDictionary metadata) in C:\Projects\monotorrent\src\MonoTorrent.Client\MonoTorrent\EditableTorrent.cs:line 123
   at MonoTorrent.TorrentCreator..ctor(TorrentType type, Factories factories) in C:\Projects\monotorrent\src\MonoTorrent.Client\MonoTorrent\TorrentCreator.cs:line 178
   at MultiUploader.Helpers.Torrents.<CreateTorrentAsync>d__0.MoveNext()
Exception type : System.BadImageFormatException
Message : Cannot load a reference assembly for execution.
alanmcgovern commented 2 months ago

Could you confirm which .net framework version you're targeting for your application?

foxi69 commented 2 months ago

.NET Framework 4.7.2 with VS Installer Project... they still don't like each other

alanmcgovern commented 2 months ago

https://www.nuget.org/packages/MonoTorrent#dependencies-body-tab

According to nuget the dependency has been specified correctly for net472.

Are you using an SDK style project, or a regular project? If it's a regular one then you might have to add those references manually. They should transitively apply if you have an SDK style project though.

I'll double check later, but at first glance it doesn't look obviously broken

alanmcgovern commented 2 months ago

This csproj file resulted in the correct set of files in the output directory, and MonoTorrent works as expected:

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

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net472</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="MonoTorrent" Version="3.0.2" />
  </ItemGroup>

</Project>

output_directory

.NET Framework 4.7.2 with VS Installer Project

I'm no expert with the VS Installer project. If it can't cope with regular csproj, then either manually referencing every binary explicitly, or (perhaps?) manually referencing every relevant nuget package, should ensure the correct set of binaries are packaged. From a "NuGet package" perspective, I'm not aware of anything I can do to help in your situation.

If there are package settings/properties i can set to make this work, do let me know though!

alanmcgovern commented 2 months ago

I'll close this as the package seems correctly set up. The odds are high the issue lies with the vs installer project, or your usage of it.