Skip to content

Commit 4d5a8c3

Browse files
committed
Clarify WebAssembly and native loading guidance
1 parent afdc91f commit 4d5a8c3

2 files changed

Lines changed: 19 additions & 4 deletions

File tree

docs/docfx/articles/getting-started/installation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ Add the following properties to the project file:
9797
</PropertyGroup>
9898
```
9999

100-
The larger initial heap accommodates the statically linked OpenCV runtime. `WasmAllowUndefinedSymbols` is currently required because the managed assembly declares APIs for OpenCV modules that are not included in the WebAssembly build; calling one of those unavailable APIs will still fail at run time. The runtime package automatically supplies the native archive and its required exception-handling setting.
100+
The larger initial heap accommodates the statically linked OpenCV runtime. `WasmAllowUndefinedSymbols` is currently a package and toolchain-specific linker workaround: it allows the static link to complete even though the managed assembly declares APIs for OpenCV modules that are not included in the WebAssembly build. Calling one of those unavailable APIs will still fail at run time. This property does not configure exception handling; the runtime package supplies the native archive and its required `WasmEnableExceptionHandling` setting.
101101

102102
See the [OpenCvSharp Blazor sample](https://github.com/shimat/opencvsharp_blazor_sample) for a complete browser application.
103103

docs/docfx/articles/troubleshooting/native-library-loading.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,22 @@ using System.Reflection;
6969
using System.Runtime.InteropServices;
7070
using OpenCvSharp.Internal;
7171

72-
string nativeLibraryPath = Path.GetFullPath(
73-
Path.Combine("native", "OpenCvSharpExtern.dll"));
7472
Assembly openCvSharpAssembly = typeof(NativeMethods).Assembly;
73+
string openCvSharpDirectory =
74+
Path.GetDirectoryName(openCvSharpAssembly.Location)
75+
?? throw new InvalidOperationException(
76+
"Could not determine the OpenCvSharp assembly directory.");
77+
78+
string nativeFileName =
79+
OperatingSystem.IsWindows() ? "OpenCvSharpExtern.dll" :
80+
OperatingSystem.IsLinux() ? "libOpenCvSharpExtern.so" :
81+
OperatingSystem.IsMacOS() ? "libOpenCvSharpExtern.dylib" :
82+
throw new PlatformNotSupportedException();
83+
84+
string nativeLibraryPath = Path.Combine(
85+
openCvSharpDirectory,
86+
"native",
87+
nativeFileName);
7588

7689
NativeLibrary.SetDllImportResolver(
7790
openCvSharpAssembly,
@@ -88,7 +101,9 @@ NativeLibrary.SetDllImportResolver(
88101
NativeMethods.TryPInvoke();
89102
```
90103

91-
Register the resolver before the first call to any OpenCvSharp API. The resolver must target `typeof(NativeMethods).Assembly`, not the host or plugin assembly, because native resolution is scoped to the assembly containing the P/Invoke declaration. Adjust the file name in the example for the target operating system.
104+
This example expects the custom native library in a `native` directory beside `OpenCvSharp.dll`. Alternatively, obtain a fully qualified native-library path from the host's configuration. Do not derive it from the process current directory because a host can change that directory.
105+
106+
Register the resolver before the first call to any OpenCvSharp API. The resolver must target `typeof(NativeMethods).Assembly`, not the host or plugin assembly, because native resolution is scoped to the assembly containing the P/Invoke declaration.
92107

93108
Calling `NativeLibrary.Load` by itself only returns a native handle; returning that handle from the resolver connects it reliably to OpenCvSharp's `OpenCvSharpExtern` imports. `NativeMethods.TryPInvoke()` is an optional explicit pre-flight check after resolver registration and is not required for normal API calls.
94109

0 commit comments

Comments
 (0)