exception when I add package of Microsoft.ML.OnnxRuntime?

mc 7,361 Reputation points
2026-09-09T13:11:02.18+00:00

Android.Runtime.JavaProxyThrowable: '[System.NotSupportedException]: Could not activate JNI Handle 0x7ff647d7d0 (key_handle 0xd084f07) of Java type 'crc646e4b5c24e03cdbf9/MainActivity' as managed type

I am using .net application 10.0 and I add package Microsoft.ML.OnnxRuntime. 1.29.0

I do not add anycode just run it .

the repo:https://github.com/ljzj2/XMedicalAndroid

Developer technologies | .NET | .NET Multi-platform App UI
0 comments No comments

Answer accepted by question author
Nguyen Dam (WICLOUD CORPORATION) 245 Reputation points Microsoft External Staff Moderator
2026-09-10T02:03:08.75+00:00

Hello @mc ,

The error occurred due to the following line of code in your MainActivity.cs file:

private readonly InferenceSession _session = new InferenceSession(""); 

because InferenceSession() requires a valid model path, and "" is not a valid path.

Suggested fix:

var modelPath = Path.Combine(CacheDir.AbsolutePath, "all-MiniLM-L6-v2.onnx"); // replace with your model file name 
using (var modelStream = Assets.Open("models/all-MiniLM-L6-v2.onnx")) // replace with the actual asset path 
using (var modelFile = File.Create(modelPath)) 
{ 
modelStream.CopyTo(modelFile); 
} 
_session = new InferenceSession(modelPath); 

Note 1: While this is not directly related to the reported error, the path used for the vocabulary file also appears to be incorrect. Since the file is located under the Models folder, you should update the reference from vocab.txt to Models/vocab.txt.

Note 2: ONNX Runtime can only load ONNX models (.onnx). If your project contains an Apple Core ML model (.mlmodel), it cannot be loaded through InferenceSession. In that case, you would need to use an ONNX version of the model instead.

If you found my response helpful or informative, I would greatly appreciate it if you could follow this guide for your confirmation. Thank you. 

Was this answer helpful?

1 person found this answer helpful.

0 additional answers

Sort by: Newest

Your answer

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