Skip to content

0.107.0 LibTorchSharp.dll fails to load (0x8007007F) on Windows x64 + ARM64 due to libtorch 2.10.0 archive header/binary mismatch #1567

@cm4ker

Description

@cm4ker

Hi I faced with issue with version TorchSharp for my project.

Here is a Agent analysis of problem and repro:

TorchSharp 0.107.0 fails to load LibTorchSharp.dll at first API call on both Windows x64 and Windows ARM64, throwing DllNotFoundException with HResult 0x8007007F (ERROR_PROC_NOT_FOUND). The misleading top-level message is "This application or script uses TorchSharp but doesn't contain a reference to libtorch-cpu-win-arm64, Version=2.10.0.0", but the project does reference both TorchSharp 0.107.0 and the matching libtorch-cpu-win-* 2.10.0 NuGet — TorchSharp's loader finds and consolidates them correctly; the OS PE loader is the one refusing the module.

Root cause is an ABI mismatch between the shipped LibTorchSharp.dll and the libtorch 2.10.0 binaries in the libtorch-cpu-win-x64 / libtorch-cpu-win-arm64 NuGet packages. Walking LibTorchSharp.dll's import table and comparing against the export tables of the bundled torch_cpu.dll / c10.dll, 16 imports cannot be resolved. Examples (mangled names omitted, both x64 and ARM64 affected identically):

LibTorchSharp.dll imports torch_cpu.dll / c10.dll 2.10.0 exports
torch::inductor::AOTIModelPackageLoader(string, string, bool, size_t, DeviceIndex) — 5 args (string, string, bool) — 3 args
c10::MessageLogger(const char*, int, int, bool) — 4 args (const char*, int, int) — 3 args
at::Context::allowTF32CuDNN(std::optional) const at::Context::allowTF32CuDNN() const
at::Context::allowFP16ReductionCuBLAS() const → CuBLASReductionOption → bool
GridSampleFuncOptions::mode(variant<kBilinear, kNearest, kBicubic>) variant<kBilinear, kNearest> (no kBicubic)
caffe2::TypeMeta::toScalarType() const caffe2::TypeMeta::toScalarType() (non-const)
`c10::*::(try_)?(incref decref)_pyobjectonTensorImpl/StorageImpl/intrusive_ptr_target`

Reproduce
repro.zip

RID : win-arm64
OS : Microsoft Windows 10.0.26200
.NET : 8.0.27

base dir : C:\Users\cmake\Downloads\repro-torchsharp-arm64\src\bin\Debug\net8.0\win-arm64
native dir : C:\Users\cmake\Downloads\repro-torchsharp-arm64\src\bin\Debug\net8.0\win-arm64
aoti_custom_ops.dll 229 888 bytes
armpl_lp64.dll 37 806 080 bytes
backend_with_compiler.dll 214 016 bytes
c10.dll 1 065 472 bytes
Google.Protobuf.dll 409 368 bytes
ICSharpCode.SharpZipLib.dll 246 272 bytes
jitbackend_test.dll 177 664 bytes
libSkiaSharp.dll 8 084 920 bytes
LibTorchSharp.dll 1 848 760 bytes
Repro.dll 7 168 bytes
SkiaSharp.dll 432 568 bytes
torch.dll 9 728 bytes
torchbind_test.dll 558 080 bytes
TorchSharp.dll 1 556 920 bytes
torch_cpu.dll 105 576 960 bytes
torch_global_deps.dll 9 728 bytes
uv.dll 208 384 bytes

package: libtorch-cpu-win-arm64

Version 0.107.0

README.md

Fill free ping me for more information. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions