Skip to content

Remove obsolete native preflight helpers - #2095

Merged
shimat merged 2 commits into
mainfrom
remove-obsolete-native-preflight
Jul 26, 2026
Merged

shimat merged 2 commits into
mainfrom
remove-obsolete-native-preflight

Conversation

@shimat

@shimat shimat commented Jul 26, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • remove NativeMethods.LoadLibraries() and NativeMethods.TryPInvoke() from OpenCvSharp5
  • remove the silent native error-handler export that existed only for LoadLibraries()
  • document that normal calls use .NET native-library resolution and recommend Cv2.GetVersionString() only when eager validation is useful
  • record the breaking API removal in the OpenCvSharp4-to-5 migration guide and update the related backlog entry
  • preserve Linux ARM64 crash sequences, full native dumps, and TRX output as failure artifacts so intermittent testhost crashes can be diagnosed without reproducing them

This PR now targets main after its original parent, #2094, was merged.

Why

OpenCvSharp5 runtime packages already use the standard runtimes/{rid}/native layout, so the .NET runtime resolves OpenCvSharpExtern on the first ordinary API call. The helpers duplicated that behavior, exposed an internal pre-flight API without adding loader guarantees, and installed an error callback whose only effect was suppressing OpenCV's stderr diagnostics. Native exceptions continue to propagate through the existing cvTry / core_getLastException path.

The first Linux ARM64 CI run after rebasing crashed with exit code 139 during testhost teardown after all 698 tests had completed (679 passed and 19 skipped). The same code had passed in the preceding run, the parent PR's ARM64 job passed, every other platform passed, and rerunning the failed job also passed. No implementation change was indicated, but the workflow previously discarded its TRX and did not enable crash blame or upload a dump. The added diagnostics ensure the next intermittent crash leaves an executed-test sequence and native dump.

Impact

Most applications require no replacement. Hosts that keep the native library in a nonstandard location should register NativeLibrary.SetDllImportResolver for typeof(NativeMethods).Assembly before the first OpenCvSharp API call. Applications that want eager validation can call Cv2.GetVersionString().

OpenCvSharp4 is unchanged.

Validation

  • cmake --build src/build --config Release --target OpenCvSharpExtern
  • dotnet build src/OpenCvSharp/OpenCvSharp.csproj -c Release --no-restore
  • dotnet test test/OpenCvSharp.Tests/OpenCvSharp.Tests.csproj -c Release --no-restore --filter "FullyQualifiedName~OpenCvSharp.Tests.ExceptionTest" (5 passed)
  • docfx docs/docfx/docfx.json (0 errors; 2 pre-existing duplicate-source warnings)
  • reran failed Linux ARM64 job successfully: https://github.com/shimat/opencvsharp/actions/runs/30198307527
  • git diff --check

Summary by CodeRabbit

  • Documentation

    • Clarified native library loading and configuration guidance for nonstandard locations.
    • Updated migration documentation to explain removed library-loading helpers and recommended runtime resolver configuration.
    • Revised troubleshooting examples to show eager validation through a standard OpenCvSharp API.
  • Bug Fixes

    • Improved native library resolution by relying on runtime loading during the first OpenCvSharp API call.
    • Removed obsolete silent native error-handler behavior, supporting clearer exception propagation.

@shimat shimat added the enhancement New feature or improvement to OpenCvSharp label Jul 26, 2026 — with ChatGPT Codex Connector
@shimat shimat self-assigned this Jul 26, 2026
@shimat
shimat force-pushed the remove-obsolete-native-preflight branch from 97cf260 to 428e0d9 Compare July 26, 2026 10:27
Base automatically changed from docs/refine-opencv-python-comparison to main July 26, 2026 10:56
@shimat
shimat force-pushed the remove-obsolete-native-preflight branch from 428e0d9 to 7862df6 Compare July 26, 2026 11:08
@shimat
shimat marked this pull request as ready for review July 26, 2026 11:31
@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: f4ab99d0-e1d6-4dff-b83d-4fe35f2f836a

📥 Commits

Reviewing files that changed from the base of the PR and between dd55cd4 and 7862df6.

📒 Files selected for processing (8)
  • .github/workflows/linux-arm64.yml
  • docs/docfx/articles/troubleshooting/native-library-loading.md
  • docs/issue-backlog.md
  • docs/migration-4-to-5.md
  • src/OpenCvSharp/Internal/PInvoke/NativeMethods/NativeMethods.cs
  • src/OpenCvSharp/Internal/PInvoke/NativeMethods/core/NativeMethods_core.cs
  • src/OpenCvSharpExtern/core.h
  • test/OpenCvSharp.Tests/system/ExceptionTest.cs
💤 Files with no reviewable changes (2)
  • src/OpenCvSharp/Internal/PInvoke/NativeMethods/core/NativeMethods_core.cs
  • src/OpenCvSharpExtern/core.h

📝 Walkthrough

Walkthrough

The change removes explicit native-loading and silent error-handler helpers, updates native-library resolver and migration documentation, and adds full crash-dump collection to ARM64 test workflow failures.

Changes

Native loading behavior

Layer / File(s) Summary
Runtime native resolution and error handling
src/OpenCvSharp/Internal/PInvoke/NativeMethods/..., src/OpenCvSharpExtern/core.h, test/OpenCvSharp.Tests/system/ExceptionTest.cs
NativeMethods loading helpers, static initialization, and silent error-handler bindings are removed; exception test documentation is renamed.
Resolver and migration guidance
docs/docfx/articles/troubleshooting/native-library-loading.md, docs/issue-backlog.md, docs/migration-4-to-5.md
Documentation describes runtime resolution, resolver registration, and eager validation through Cv2.GetVersionString().

ARM64 crash diagnostics

Layer / File(s) Summary
Crash-enabled ARM64 test workflow
.github/workflows/linux-arm64.yml
ARM64 tests enable full crash dumps and upload dump artifacts when the job fails.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested labels: bug

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly reflects the main change: removing obsolete native preflight helpers and related native loading APIs.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch remove-obsolete-native-preflight

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@shimat
shimat merged commit 3b61aaf into main Jul 26, 2026
17 checks passed
@shimat
shimat deleted the remove-obsolete-native-preflight branch July 26, 2026 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or improvement to OpenCvSharp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant