Skip to content

Inline the one PInvokeHelper use and delete the class - #1973

Merged
shimat merged 1 commit into
5.xfrom
feature/remove-pinvokehelper-5x
Jun 28, 2026
Merged

shimat merged 1 commit into
5.xfrom
feature/remove-pinvokehelper-5x

Conversation

@shimat

@shimat shimat commented Jun 28, 2026

Copy link
Copy Markdown
Owner

@
Small cleanup (independent of the #1968–#1972 stack; based on 5.x).

PInvokeHelper had only two members:

  • CreateException(Exception) — used in exactly one place, NativeMethods.TryPInvoke, to wrap a DLL-load failure as OpenCvSharpException.
  • DllImportError(Exception) — dead (no callers).

Inline the trivial new OpenCvSharpException(e.Message, e) at the two TryPInvoke call sites and delete the class.

TryPInvoke is kept (on purpose)

It has no callers, but that is by design: since #1753 it is no longer invoked automatically (the old static-constructor call ran the first P/Invoke before user code could register a custom NativeLibrary.SetDllImportResolver). It remains public as an opt-in pre-flight DLL-load check that returns a friendly error for the most common support issue ("Unable to load DLL OpenCvSharpExtern"). So only the helper class is removed, not the diagnostic.

Managed build green.
@

PInvokeHelper had only two members: CreateException (used solely by
NativeMethods.TryPInvoke to wrap a DLL-load failure) and DllImportError (dead,
no callers). Inline the trivial `new OpenCvSharpException(e.Message, e)` at the
two TryPInvoke call sites and delete the class.

TryPInvoke itself is kept: since #1753 it is no longer called automatically
(that broke custom NativeLibrary.SetDllImportResolver registration) but remains
public as an opt-in pre-flight DLL-load check.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@shimat shimat self-assigned this Jun 28, 2026
@shimat
shimat merged commit 18abb18 into 5.x Jun 28, 2026
14 checks passed
@shimat
shimat deleted the feature/remove-pinvokehelper-5x branch June 28, 2026 11:10
@shimat shimat added the enhancement New feature or improvement to OpenCvSharp label Jul 25, 2026
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