Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 27, 2025

On case-sensitive filesystems (Windows with WSL, developer mode, or per-directory case sensitivity), DllImport fails to load native libraries due to relying on .NET's automatic platform-specific extension/prefix addition, which can produce incorrect casing.

Changes

  • NativeMethods.shared.cs: Changed desktop platform library names from "onnxruntime" to "onnxruntime.dll" and "ortextensions" to "ortextensions.dll"
  • Explicitly specifying extensions ensures consistent behavior across case-sensitive and case-insensitive filesystems
  • Android/iOS platform-specific names unchanged

Impact

Windows: No changes required - libraries already named onnxruntime.dll

Linux/macOS: Native packaging may need updates to provide onnxruntime.dll in runtime folders (either as actual filename or symlink to libonnxruntime.so/libonnxruntime.dylib)

// Before (relied on automatic extension addition)
internal const string DllName = "onnxruntime";

// After (explicit extension for consistency)
internal const string DllName = "onnxruntime.dll";

Fixes #23509

Original prompt

This section details on the original issue you should resolve

<issue_title>Does not work on case-sensitive filesystems</issue_title>
<issue_description>### Describe the issue

Library does not work on case-sensitive filesystems. We get:

Unhandled exception. System.TypeInitializationException: The type initializer for 'Microsoft.ML.OnnxRuntime.NativeMethods' threw an exception.
 ---> System.EntryPointNotFoundException: Unable to find an entry point named 'OrtGetApiBase' in DLL 'onnxruntime'.
   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 Program.<Main>$(String[] args) in Z:\temp\onnxtest\Program.cs:line 1

Probably due to a mistyped filename somewhere.

To reproduce

Create new C# project, use this Program.cs:

new Microsoft.ML.OnnxRuntime.InferenceSession("");

Urgency

No response

Platform

Windows

OS Version

Microsoft Windows [Version 10.0.19045.6332]

ONNX Runtime Installation

Released Package

ONNX Runtime Version or Commit ID

1.22.1

ONNX Runtime API

Other / Unknown

Architecture

X64

Execution Provider

Other / Unknown

Execution Provider Library Version

No response</issue_description>

Comments on the Issue (you are @copilot in this section)

@snnn I checked the code, still do not have much clue. We didn't specify the extension name. Maybe it was added by the .net runtime.

https://github.com/microsoft/onnxruntime/blob/main/csharp/src/Microsoft.ML.OnnxRuntime/NativeMethods.shared.cs#L831</comment_new>
<comment_new>@snnn

Maybe we should just specify explicit extensions then in DllImport

That might be the easiest fix. Would like to submit a PR?</comment_new>
<comment_new>@snnn
Don't close it.</comment_new>


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

…lesystem issues

Co-authored-by: snnn <856316+snnn@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix library compatibility with case-sensitive filesystems Fix DllImport library names for case-sensitive filesystems Oct 27, 2025
Copilot AI requested a review from snnn October 27, 2025 17:19
Copilot finished work on behalf of snnn October 27, 2025 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Does not work on case-sensitive filesystems

2 participants