Fix IL3000 trimming warning in WindowsLibraryLoader - #1884
Conversation
Replace Assembly.Location with AppContext.BaseDirectory. Assembly.Location returns an empty string in single-file and AoT published apps, triggering IL3000 trimming warnings. AppContext.BaseDirectory is the correct alternative and is available across all current target frameworks (netstandard2.0, netstandard2.1, net8.0). The previous code already fell back to AppContext.BaseDirectory on the very next attempt, so the Assembly.Location lookup was also redundant. Remove the now-dead #if !NET40 guard (NET40 is never defined in this project; the minimum consumable framework via netstandard2.0 is .NET 4.6.1, where AppContext.BaseDirectory is available unconditionally). Remove the no-longer-needed `using System.Reflection` import. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
📝 WalkthroughWalkthroughThis PR removes reflection-based library path detection from ChangesWindowsLibraryLoader and documentation
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
docs/issue-backlog.md (1)
1-121:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winSave this Markdown file as UTF-8 with BOM.
This new
.mdfile appears to be checked in without the required BOM marker. Please resave it as UTF-8 with BOM to match repo policy.As per coding guidelines,
**/*.{cs,csproj,yml,md,json}: All source files must be saved as UTF-8 with BOM (EF BB BF)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@docs/issue-backlog.md` around lines 1 - 121, The file docs/issue-backlog.md was committed without the required UTF-8 BOM; reopen docs/issue-backlog.md, resave it encoded as "UTF-8 with BOM" (EF BB BF) using your editor/IDE or iconv/PowerShell, verify the BOM is present at the top of the file, then stage and commit the change (or amend the existing commit) so the repo policy for UTF-8-with-BOM on markdown and other source files is satisfied.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@docs/issue-backlog.md`:
- Around line 1-121: The file docs/issue-backlog.md was committed without the
required UTF-8 BOM; reopen docs/issue-backlog.md, resave it encoded as "UTF-8
with BOM" (EF BB BF) using your editor/IDE or iconv/PowerShell, verify the BOM
is present at the top of the file, then stage and commit the change (or amend
the existing commit) so the repo policy for UTF-8-with-BOM on markdown and other
source files is satisfied.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: eaa569af-943b-4a17-9169-7e01ef89541a
📒 Files selected for processing (3)
.gitignoredocs/issue-backlog.mdsrc/OpenCvSharp/Internal/PInvoke/WindowsLibraryLoader.cs
Fixes #1766
Problem
WindowsLibraryLoader.LoadLibraryusedAssembly.Locationto determine the base directory for native DLL lookup. In single-file and AoT published apps,Assembly.Locationalways returns an empty string and causes the IL3000 trimming warning at publish time.Changes
Assembly.LocationwithAppContext.BaseDirectory, which is the correct alternative for all publish modes including single-file and AoT.AppContext.BaseDirectoryon the very next attempt, making theAssembly.Locationpath both broken and unnecessary.#if !NET40/#elseguard.NET40is never defined in this project. The minimum consumable framework vianetstandard2.0is .NET 4.6.1, whereAppContext.BaseDirectoryis unconditionally available.using System.Reflectionimport.AppContext.BaseDirectoryis available across all current target frameworks (netstandard2.0,netstandard2.1,net8.0), so there is no regression for any supported target.Summary by CodeRabbit
Release Notes
Documentation
Chores