onnxruntime: Unable to load DLL 'onnxruntime.dll': The specified module could not be found.
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
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows
- ONNX Runtime installed from (source or binary): Nuget Installed Microsoft.ML.OnnxRuntime in VS17
- ONNX Runtime version: 0.1.5
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.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 6
- Comments: 28 (7 by maintainers)
I don’t understand why this is closed. Shouldn’t the nuget package copy the native file automatically?
I struggled with this until I fired up “Depends” and discovered that it requires the VC runtime.
I did some digging to see if I could find a solution to your issue but was unable to locate any x86 binaries. I think your best bet might be to download the source code from Microsoft.ML source code and try to build your desired x86 libs.
Keep in mind not all functionalities when running x86 are supported, specifically TensorFlow and LightGBM. This is stated in the github for ML. Another reference to x86 not being supported here. Who knows what issues might arise when trying to build the lib with your setup so I would suggest migrating your project to x64 if possible.
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, Nullable
1 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’ve had similar problems with onnxruntime.dll when deploying my application on other computers.
In the end it came down to installing “Visual C++ Redistributable for Visual Studio” (VC_redist.x64.exe & VC_redist.x86.exe). After installing these libraries the problem was resolved and onnxruntime.dll loaded without problems.
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.