TorchSharp: This application or script uses TorchSharp but doesn't contain a reference to libtorch-cpu-11.3-win-x64, Version=1.11.0.1

Having some trouble using Torchsharp in a C# .Net 4.8 project. I’d show you some source code but this is as far as i’ve gotten:

TryInitializeDeviceType(TorchSharp.DeviceType.CPU); Replacing this code with any other code from Torchsharp-library creates the same result and error.

I’m using the Torchsharp-cpu nuget package, and I’ve tried using Torchsharp with the libtorch-cpu-11.3-win-x64 package and its dependencies as well without any luck.

My packages.config includes these: <package id="libtorch-cpu" version="1.13.0.1" targetFramework="net48" /> <package id="libtorch-cpu-linux-x64" version="1.13.0.1" targetFramework="net48" /> <package id="libtorch-cpu-osx-x64" version="1.13.0.1" targetFramework="net48" /> <package id="libtorch-cpu-win-x64" version="1.13.0.1" targetFramework="net48" /> And I’ve tried using the exact 1.11.0 version with no luck as well.

Not really sure how to proceed to make it work here.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 36 (32 by maintainers)

Most upvoted comments

For now, I’m going to add a runtime check that we’re running in 64-bit mode before trying to load DLLs. That should at least help by generating a more directly understandable error message. Still won’t address the core issue.

These steps I already tried but I love to hear if this worked for all you.

This worked in my test project!

Here is how you can try to work around the issue with the old projects:

  • Clean your project from old, referenced packages. I mean in the NuGet package manager, uninstall all referenced NuGet packages (like TorchSharp and TorchSharp-cpu).
  • delete the file packages.config
  • try to change the Default Package Management option in the Options UI to PackageReference image
  • Right click on your project in the solution explorer and choose clean
  • manually go to NuGet manager in your project and start adding the dependencies on the packages TorchSharp and TorchSharp-cpu.
  • Compile and run.

These steps I already tried but I love to hear if this worked for all you.

Yeah, it’s VS / dotnet that’s not copying all the transitive dependencies (TorchSharp is there, but not all the libtorch DLLs), so if you do a clean, it’s going to make the same mistake again.

a fresh solution should work?

Just do a clean of the obj + bin folders. Remove the TorchSharp-cpu package dependency and add it back in. If there’s some weird setting to not copy transitive dependencies (I don’t think there is, I have never heard of one), make sure that it’s not set.