Skip to content
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

NativeMethod failed with NullReferenceException under c# ONNX in Windows_NT #21309

Open
darren-zdc opened this issue Jul 10, 2024 · 1 comment
Assignees
Labels
api:CSharp issues related to the C# API .NET Pull requests that update .net code platform:windows issues related to the Windows platform

Comments

@darren-zdc
Copy link

Describe the issue

I have a C# unit test that load an ONNX model and do a prediction. The test works well in my Windows 11 box. But when I tested it in my Windows Server, it failed with a nullreference exception.

I wonder if the ONNX runtime package is compatible with Windows_NT.

Error message:

  Failed Datahunter.Tests.BertSentenceSimilarity.NLPSearchTest.GivenTwoTitles_ThenFindOutSimilarityScore(title1: "Battery technologies mass weighted SDP", title2: "battery life cycle", expectedScore: 0.92900002) [508 ms]
  Error Message:
   System.TypeInitializationException : The type initializer for 'Microsoft.ML.OnnxRuntime.NativeMethods' threw an exception.
---- System.NullReferenceException : Object reference not set to an instance of an object.
  Stack Trace:
     at Microsoft.ML.OnnxRuntime.SessionOptions..ctor()
   at Microsoft.ML.OnnxRuntime.InferenceSession..ctor(String modelPath)
   at Datahunter.Tests.BertSentenceSimilarity.NLPSearchTest.GivenTwoTitles_ThenFindOutSimilarityScore(String title1, String title2, Single expectedScore) in D:\vsts-agent-win-x64-3.225.0\_work\60\s\DataHunter-Main\tests\Datahunter.Tests\BertSentenceSimilarity\NLPSearchTest.cs:line 95
--- End of stack trace from previous location ---
----- Inner Stack Trace -----
   at Microsoft.ML.OnnxRuntime.NativeMethods..cctor()

System information:
OS: Windows_NT
OSArchitecture: x64
OSVersion: 10.0.20348

To reproduce

in a Windows_NT box,
run a dotnet net unit test to load an ONNX model.
I have something like these.

 private string _baseUncasedModelFromPytorchPath = @"BertSentenceSimilarity/bert-base-uncased.onnx";

 public async Task GivenTwoTitles_ThenFindOutSimilarityScore(string title1, string title2, float expectedScore)
 {
     // Arrange
     // Create an InferenceSession from the Model Path.
     using var session = new InferenceSession(Path.GetFullPath(_baseUncasedModelFromPytorchPath));
     using var runOptions = new RunOptions();
 }

Urgency

No response

Platform

Windows

OS Version

10.0.20348

ONNX Runtime Installation

Released Package

ONNX Runtime Version or Commit ID

1.18.0

ONNX Runtime API

C#

Architecture

X64

Execution Provider

Default CPU

Execution Provider Library Version

No response

@github-actions github-actions bot added model:transformer issues related to a transformer model: BERT, GPT2, Hugging Face, Longformer, T5, etc. platform:windows issues related to the Windows platform labels Jul 10, 2024
@sophies927 sophies927 added .NET Pull requests that update .net code api:CSharp issues related to the C# API and removed model:transformer issues related to a transformer model: BERT, GPT2, Hugging Face, Longformer, T5, etc. labels Jul 11, 2024
@amusingCloud
Copy link

I'm also facing same NullReferenceException at Microsoft.ML.OnnxRuntime.NativeMethods..cctor().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api:CSharp issues related to the C# API .NET Pull requests that update .net code platform:windows issues related to the Windows platform
Projects
None yet
Development

No branches or pull requests

5 participants