Skip to content

OnnxRuntime 1.21.0 Java package failed to load on Windows #24287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
frankfliu opened this issue Apr 3, 2025 · 6 comments
Open

OnnxRuntime 1.21.0 Java package failed to load on Windows #24287

frankfliu opened this issue Apr 3, 2025 · 6 comments
Labels
api:Java issues related to the Java API platform:windows issues related to the Windows platform

Comments

@frankfliu
Copy link
Contributor

Describe the issue

I got the following exception when calling new OrtEnvironment.ThreadingOptions()

C:\Users\Administrator\AppData\Local\Temp\2\onnxruntime-java12888664878249579864\onnxruntime.dll: A dynamic link library (DLL) initialization routine failed
java.lang.UnsatisfiedLinkError: C:\Users\Administrator\AppData\Local\Temp\2\onnxruntime-java12888664878249579864\onnxruntime.dll: A dynamic link library (DLL) initialization routine failed
	at java.base/jdk.internal.loader.NativeLibraries.load(Native Method)
	at java.base/jdk.internal.loader.NativeLibraries$NativeLibraryImpl.open(NativeLibraries.java:388)
	at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:232)
	at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:174)
	at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2389)
	at java.base/java.lang.Runtime.load0(Runtime.java:755)
	at java.base/java.lang.System.load(System.java:1953)
	at ai.onnxruntime.OnnxRuntime.load(OnnxRuntime.java:387)
	at ai.onnxruntime.OnnxRuntime.init(OnnxRuntime.java:166)
	at ai.onnxruntime.OrtEnvironment$ThreadingOptions.<clinit>(OrtEnvironment.java:510)

The code works with 1.20.0. I tried use dumpbin the check the dependency, didn't find anything obvious. The dependencies looks the same as 1.20.0.

To reproduce

See: https://github.com/deepjavalibrary/djl/actions/runs/14225872126/job/39865137732#step:16:174

Urgency

No response

Platform

Windows

OS Version

Windows Server 2022

ONNX Runtime Installation

Released Package

ONNX Runtime Version or Commit ID

1.21.0

ONNX Runtime API

Java

Architecture

X64

Execution Provider

Default CPU

Execution Provider Library Version

No response

@github-actions github-actions bot added platform:windows issues related to the Windows platform api:Java issues related to the Java API labels Apr 3, 2025
@Craigacp
Copy link
Contributor

Craigacp commented Apr 3, 2025

This is due to a change in the VC++ redist that is used to compile the native library. If it differs from the JVM one then it fails, you can see more information here - #23971. I'm hitting this in Tribuo too, but I've not had time to try and figure out a better solution that works for more users so I've not upgraded to 1.21.0.

@frankfliu
Copy link
Contributor Author

Majority of java user still use JDK 17, and there are large percentage is still using JDK 11 and 8. I that possible to downgrade to 14.36?

@Craigacp
Copy link
Contributor

Craigacp commented Apr 3, 2025

It's not a JVM version issue, I think Oracle Java SE 24 is compiled with the older version. I think Adoptium 8u442 is compiled against the latest version, as are some versions of Microsoft's build of OpenJDK.

I think my preferred solution is to statically link the VC dist for the java build on Windows but I've not tested it works nor am I sure that MS will think that's a good solution.

@Craigacp
Copy link
Contributor

Craigacp commented Apr 3, 2025

The classes still seem to be compiled with Java 8, though the build.gradle targets 17. I don't understand how that happened, but I don't do the builds.

@snnn
Copy link
Member

snnn commented Apr 7, 2025

Majority of java user still use JDK 17, and there are large percentage is still using JDK 11 and 8. I that possible to downgrade to 14.36?

Please note that Visual Studio 2022 version 17.6 and anything older are out of support(EOL). It means anyone who wants to build a DLL that can be run with JDK 17 would put themselves in danger. So, I suggest Oracle provides an update to the JRE versions with an updated version of MSVC runtime. They don't need to recompile their binaries.

I think my preferred solution is to statically link the VC dist for the java build on Windows but I've not tested it works nor am I sure that MS will think that's a good solution.

Usually the major concern is security. If MSVC runtime is part of the ONNX Runtime binaries, then whenever MSVC runtime had a security update ONNX Runtime needs to do a security update too. However, now JRE and conda provide a copy of MSVC runtime along with their exes. If they do not keep the DLLs to update, essentially the security posture is the same.

@Craigacp
Copy link
Contributor

Craigacp commented Apr 7, 2025

Oracle Java SE is updated according to it's own schedule, that team will investigate it on their end.

Replacing msvcp140.dll in the JDK seems to work for some users who've hit this on either ONNX Runtime or other libraries, though I expect that's not supported by people who provide support for OpenJDK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api:Java issues related to the Java API platform:windows issues related to the Windows platform
Projects
None yet
Development

No branches or pull requests

3 participants