Skip to content

[Mobile] Microsoft.ML.OnnxRuntime.Managed MacCatalyst regression in 1.22.1. System.TypeInitializationException when accessing library APIs. #25342

Open
@tuanchien

Description

@tuanchien

Describe the issue

Likely regression in Microsoft.ML.OnnxRuntime.Managed 1.22.1. This problem does NOT occur in 1.22.0.

Tested configurations

  • Microsoft.ML.OnnxRuntime.Managed (1.22.1) + Microsoft.ML.OnnxRuntime (1.22.1) - BROKEN
  • Microsoft.ML.OnnxRuntime.Managed (1.22.1) + Microsoft.ML.OnnxRuntime(1.22.0) - BROKEN
  • Microsoft.ML.OnnxRuntime.Managed (1.22.0) + Microsoft.ML.OnnxRuntime (1.22.0) - OK

Environment

  • dotnet (sdk 9.0.302 with 9.0.7 runtime)
  • MAUI MacCatalyst
  • Runtime machine: MacOS Sequoia 15.5 running on a M1.

Issue

Attempting to access a library api, e.g.,

OrtEnv.Instance();

will throw:

Exception has occurred: CLR/System.TypeInitializationException
An unhandled exception of type 'System.TypeInitializationException' occurred in Microsoft.MacCatalyst.dll: 'The type initializer for 'Microsoft.ML.OnnxRuntime.NativeMethods' threw an exception.'
 Inner exceptions found, see $exception in variables window for more details.
 Innermost exception 	 System.DllNotFoundException : onnxruntime
<Cannot evaluate the exception stack trace>

To reproduce

Minimum code example:
https://github.com/tuanchien/onnxruntime-1-22-1-maccatalyst-typeinitialization-exception.git

It's a dotnet new maui project, with the nuget project references added, and a call to OrtEnv.Instance() added to the button press driver method.

Urgency

No response

Platform

MAUI

OS Version

MacOS 15.5

ONNX Runtime Installation

Released Package

Compiler Version (if 'Built from Source')

No response

Package Name (if 'Released Package')

Microsoft.ML.OnnxRuntime.Managed

ONNX Runtime Version or Commit ID

1.22.1

ONNX Runtime API

C#

Architecture

ARM64

Execution Provider

Default CPU

Execution Provider Library Version

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    .NETPull requests that update .net codeapi:CSharpissues related to the C# APIplatform:mobileissues related to ONNX Runtime mobile; typically submitted using template

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions