How to reference the native Onnxruntime.dll in my app installed from Nuget in my app .Instead of from System32

Vishal2 Bansal 265 Reputation points
2024-11-29T12:30:32.1733333+00:00

Requirements:-

  1. Hi i have created a .net framework class library. It uses inference session from ML.Onnxruntime nuget package to load a model and run inferencing on it.
  2. Now i am using that library in my WPF UI app. I don't want to install ML.onnxruntime in my wpf UI app as it is already installed in library. In UI app i will only pass some model test data (some sentences) to the the class library . That library should handle it and run inferencing.

Error facing:-

  1. Not able to achieve 2nd point. As my UI app is forcing me to download onnxruntime Ml package from nuget.
  2. If i install it then i am not able to run this UI app on other laptop(having windows 10). Their i guess it is referring to the onnxruntime.dll present in System32. Which is wrong. So help to me achieve my requirements.
Developer technologies | Windows Presentation Foundation
Developer technologies | .NET | Other
Developer technologies | C#
{count} votes

Accepted answer
  1. Ki-lianK-7341 935 Reputation points
    2024-11-29T12:52:05.58+00:00
    1. Copy DLLs: Ensure onnxruntime.dll is copied to your WPF app’s output directory.
    2. Set DLL Path: Add this code at the start of your app to set the DLL search path:
    
    using System;
    using System.IO;
    using System.Runtime.InteropServices;
    
    [DllImport("kernel32.dll", SetLastError = true)]
    static extern bool SetDllDirectory(string lpPathName);
    
    string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "path_to_your_dlls");
    SetDllDirectory(path);
    																																														
    
    
    
    1. Deploy Properly: Ensure all necessary DLLs are included in your deployment package.

    This should help your app reference the correct onnxruntime.dll.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.