Describe the bug
After installing Nuget package and attempting to create a session I get the following error in a WinForms app on .NET Framework version 4.6.1:
Unable to load DLL 'onnxruntime.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
at line 33 in Microsoft.ML.OnnxRuntime.SessionOptions:
public SessionOptions()
{
_nativeOption = new NativeOnnxObjectHandle(NativeMethods.ONNXRuntimeCreateSessionOptions());
}
System information
To Reproduce
Added Nuget package and attempted the following code with a valid onnx file:
var options = SessionOptions.Default;
options.AppendExecutionProvider(ExecutionProvider.Cpu);
_session = new InferenceSession(file, options);
I tried running from Visual Studio on x64
Expected behavior
The dll should load and the session should start.
Note
I am sure this is a silly error on my part but maybe others will run into it.
@shahasad @jignparm can one of you take a look? thanks!
Current build is supported for windows 10, x64 CPU only. Support for other platforms are coming in subsequent releases. Meanwhile, please feel free to build from the source.
I built from source but could not find the dll. I鈥檓 also running Windows 10 x64.
The problem is due to the Visual Studio not copying the dependent dlls (onnxruntime.dll and mkldnn.dll )to the x64Debug directory. After copying both these files, the project runs successfully.
That is correct! Also the onnx model I exported from the current version of the PyTorch ONNX export uses a version of Gemm in the export that is not compatible.
I don't understand why this is closed. Shouldn't the nuget package copy the native file automatically?
Same issue here.
Should have been fixed in the later versions. Plz try v0.5
I have the same thing on 0.5
I have the same thing on 1.1.0
You have to set your cpu type to either x86 or x64.
@shahasad @jignparm Perhaps this could be made clearer, maybe build should fail if cpu type is not correctly setup in Visual Studio.
You have to set your cpu type to either x86 or x64.
I have the same thing on 1.1.0
That should not be the case -- it should work for x86, x64 as well as AnyCPU, depending on which architecture applies to the project (i.e. native C++, .Net Core or .Net Framework).
The package ships with the appropriate targets files, so you should not need to copy any DLLs (the original issue was created prior to the package fixes.)
Can you post a way to reproduce the error?
To be honest I haven't tried to reproduce since the 0.4 era, I only pinged you because I saw someone saying they had it with 1.1.0. I still do leave mine configured with x86 regardless of whether my code is managed or not. If I have time I'll experiment.
I believe one issue was fixed by changing the platform, but I have not tried to replicate the problem.
One thing I know for sure: I have a project - project A - that uses onnxruntime as a nuget package. I have another project - project B - that references project A. Unless onnxtruntime is explicitly added as a Nuget package to project B, onnxtruntime.dll doesn't get copied into the bin folder. I think this is a property of Nuget more generally, and not onnxruntime per se.
It happens to me also on 1.1.1, and without a way to reproduce it for now
I figured out my issue!
I am using _paket_ as a package manager, instead of VS nuget manager. So my project doesn't have a packages.config, which is why onnxruntime.dll is never copied
props.xml has the following conditions:
<ItemGroup Condition="Exists('packages.config') OR
Exists('$(MSBuildProjectName).packages.config') OR
Exists('packages.$(MSBuildProjectName).config')">
I will be creating a new issue for this
I've had this error with Microsoft.ML.OnnxRuntime.Gpu 1.3.0
Turns out, I've accidently removed "NVIDIA GPU Computing Toolkit" from the path.
i'm having the same issue on 1.4.2
any suggestion ?
System.TypeInitializationException: The type initializer for 'Microsoft.ML.OnnxR
untime.NativeMethods' threw an exception.
---> System.DllNotFoundException: Unable to load DLL 'onnxruntime' or one of it
s dependencies: The specified module could not be found. (0x8007007E)
at Microsoft.ML.OnnxRuntime.NativeMethods.OrtGetApiBase()
at Microsoft.ML.OnnxRuntime.NativeMethods..cctor()
--- End of inner exception stack trace ---
at Microsoft.ML.OnnxRuntime.SessionOptions..ctor()
at Microsoft.ML.OnnxRuntime.InferenceSession..ctor(String modelPath)
at Microsoft.ML.Transforms.Onnx.OnnxModel..ctor(String modelFile, Nullable1
gpuDeviceId, Boolean fallbackToCpu, Boolean ownModelFile, IDictionary2 shapeDic
tionary)
OS Platform: Windows 7 64bit
ONNX Runtime installed from Nuget Microsoft.ML.OnnxRuntime in VS19
ONNX Runtime version: 1.4.2
I struggled with this until I fired up "Depends" and discovered that it requires the VC runtime.
@devnet123 I get the same error on both 1.5.1 and 1.52 versions but I have fixed it.
Here is how I fixed it:
Go to here: download onnxruntime.dll from github
I downloaded the onnxruntime-win-x64-1.5.1.zip package since it matches my OS and architecture.
Then once you have that downloaded, unzip it and go to: onnxruntime-win-x64-1.5.1lib**
You should see the *onnxruntime.dll inside there.. just leave it for now..
Keep that directory open and then go to back to your project.
Go to the directory (assuming your using .netcore and x64): binx64Debugnetcoreapp3.1runtimeswin-x64native*
What matter is you go to the **native folder.
Copy the onnxruntime.dll into that native folder which might have _LdaNative.dll_ and _tensorflow.dll_ also in it (mine does for my setup).
Now when you run your program you should be able to find that dll (module) the application was complaining about.
I hope that fixes your problem!
I was facing this issue (or possibly a similar issue), and I ended up installing https://www.nuget.org/packages/Microsoft.ML.OnnxRuntime/1.5.2?_src=template which resolved the issue for me.
Most helpful comment
I don't understand why this is closed. Shouldn't the nuget package copy the native file automatically?