-
-
Notifications
You must be signed in to change notification settings - Fork 11
Add param block to support conditional DLL loading #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Add -SkipSqlClient, -SkipAzure, -SkipSmo, and -SkipAssemblies parameters - Allow users to selectively skip DLL imports to avoid conflicts with SqlServer module - Addresses issue #32 by providing flexible DLL loading control Co-authored-by: Chrissy LeMaire <potatoqualitee@users.noreply.github.com>
|
@claude pls fix and choose options A and C, do the readme as well as the first fix you suggested |
- Fix variable reference error: use $redirector.EventHandler instead of undefined $onAssemblyResolveEventHandler - Add Option A: Support hashtable configuration via -ArgumentList parameter - Add Option C: Support module-scoped variables for cleaner syntax - Add Microsoft.Identity.Client to SkipAzure check (was missing from issue #32) - Update README with comprehensive usage examples for both configuration approaches Co-authored-by: Chrissy LeMaire <potatoqualitee@users.noreply.github.com>
|
@claude Run Import-Module ./artifacts/dbatools.library/dbatools.library.psd1 -Force
At D:\a_temp\eb268eaf-ba12-41fa-a582-3a103eabd724.ps1:2 char:1
The if ispresent is overkill. just say if ($var) or if (-not $var). and remove configuration example as suggested. pls be idiomatic and use pwoershell best practices |
- Use idiomatic PowerShell: remove .IsPresent checks, use simple boolean tests - Add Microsoft.Bcl.AsyncInterfaces to import list (required by Azure.Core) - Remove Microsoft.Data.SqlClient from desktop names array (already handled separately) - Remove Configuration hashtable parameter, use only switches and module variables - Update README to focus on module variable approach Co-authored-by: Chrissy LeMaire <potatoqualitee@users.noreply.github.com>
|
@claude we're still getting the same issue. return to how the original person fixed it, fix it that way, dont add all this extra shit and just make argument list work. Run Import-Module ./artifacts/dbatools.library/dbatools.library.psd1 -Force
At D:\a_temp\133b9382-d312-4dc6-b98d-0609813976a4.ps1:2 char:1
|
- Moved AssemblyResolve removal to after all imports complete (fixes dependency loading) - Removed module-scoped variable complexity - Removed Microsoft.Bcl.AsyncInterfaces from $names array (handled by Redirector) - Updated README with clear ArgumentList positional parameter examples - Fixes Microsoft.Bcl.AsyncInterfaces dependency error when loading Azure.Core Co-authored-by: Chrissy LeMaire <potatoqualitee@users.noreply.github.com>
|
@claude your approach is not working well. Just give it ONE parameter to skip (Come up with a best practice powershell parameter name for this action, perhaps SkipSqlServerLibrary or soemthing?) and then do tests: if the DLL is already loaded then skip. |
- Replace multiple skip parameters with single -AvoidConflicts switch - Auto-detect already-loaded assemblies to prevent conflicts - Simplify README with clearer usage examples - Use idiomatic PowerShell patterns throughout Co-authored-by: Chrissy LeMaire <potatoqualitee@users.noreply.github.com>
|
why is this not working? there should be ZERO impact if the person did not specify -AvoidConflicts Running tests from 'D:\a\dbatools.library\dbatools.library\dbatools.github\scripts\gh-winactions.ps1' |
Refactors logic to better handle the AvoidConflicts flag by skipping loading of Microsoft.Data.SqlClient and other assemblies if they are already loaded, preventing conflicts with other modules like SqlServer. Also removes redundant assembly resolver cleanup and streamlines the assembly import process.
|
@claude Fix: Must Fix: |
- Fix undefined variable reference (redirector.EventHandler) - Add Desktop edition support for -AvoidConflicts - Add verbose logging when assemblies are skipped - Fix Core edition logic that incorrectly skipped ALL assemblies - Add integration tests for AvoidConflicts functionality Co-authored-by: Chrissy LeMaire <potatoqualitee@users.noreply.github.com>
|
@claude Fix: Must Fix: add a real integration test like within gh-actions and follow my pattern. delete whatever you just created. |
|
Claude finished @potatoqualitee's task in 3m 36s —— View job Fixes completedTask List
Changes Committed1. Fixed Critical Bug (dbatools.library.psm1:122)
2. Added Desktop Edition Support
3. Enhanced Verbose Logging
4. Removed Standalone Test File
|
- Fix undefined variable error on Desktop edition (line 122) - Add Desktop edition support for -AvoidConflicts parameter - Enhance verbose logging for skipped assemblies - Add integration tests to build.yml workflow - Remove standalone test file in favor of workflow tests Co-authored-by: Chrissy LeMaire <potatoqualitee@users.noreply.github.com>
Code Review - PR #34: Add param block to support conditional DLL loadingSummaryThis PR adds an ✅ Strengths
|
🔍 Issues & RecommendationsCritical: Potential Bug in Assembly Detection Logic (Lines 195-203)Issue: The assembly detection logic queries # Line 177: assemblies captured ONCE before loop
$assemblies = [System.AppDomain]::CurrentDomain.GetAssemblies()
# Lines 195-203: Using stale $assemblies reference
if ($AvoidConflicts) {
$assemblyfullname = $assemblies.FullName | Out-String
if ($assemblyfullname.Contains("$name,")) {
$skipAssembly = $true
Write-Verbose "Skipping $name.dll - already loaded"
}
}Recommendation: Either:
Suggested Fix (if you want dynamic detection): if ($AvoidConflicts) {
$currentAssemblies = [System.AppDomain]::CurrentDomain.GetAssemblies()
$assemblyfullname = $currentAssemblies.FullName | Out-String
if ($assemblyfullname.Contains("$name,")) {
$skipAssembly = $true
Write-Verbose "Skipping $name.dll - already loaded"
}
} |
|
@claude okay add a ps1 file in tests/ i'll install the sqlserver module using psmodulecache in the yml file. add a yml file to tests/ and ill move it. then import it then import dbatools. |
Code Quality: Redundant Assembly Check (Lines 205-208)Issue: There is duplicate assembly checking logic - the code checks if an assembly is already loaded twice. Recommendation: The second check at line 208 is redundant when AvoidConflicts is true. Consider using continue to skip to the next iteration after detecting an already-loaded assembly, eliminating the need for the nested if block. |
|
Claude finished @potatoqualitee's task in 1m 52s —— View job Test files created successfully ✓Task List
Files Created1. tests/test-avoidconflicts.ps1A comprehensive test script that validates the AvoidConflicts functionality:
The test follows your repository's pattern with color-coded output, clear PASS/FAIL messages, and a summary section. 2. tests/test-avoidconflicts.ymlA GitHub Actions workflow file that:
The workflow is triggered on:
Next StepsYou mentioned you'll move the YAML file from - '.github/workflows/test-avoidconflicts.yml'to reflect its actual location. Commit: |
Code Quality: Inconsistent Assembly Detection (Lines 104-112 vs 195-203)Issue: SqlClient uses Where-Object to check if loaded, while the loop uses string matching. Two different approaches for the same operation makes the code harder to maintain. Recommendation: Use consistent approach throughout. The string-based check is actually faster for bulk operations, so consider converting the SqlClient check to match the loop logic for consistency. |
Performance: Repeated String Conversions (Line 198)Issue: When AvoidConflicts is enabled, the code converts assemblies.FullName to a string on EVERY iteration of the loop. For ~14 assemblies in the names array, this performs the string conversion 14 times unnecessarily. Impact: Moderate performance overhead during module import when -AvoidConflicts is used. Recommendation: Move the string conversion outside the loop (before line 185). Calculate it once and reuse the string throughout the loop iterations. This is a simple optimization that would improve module load time. |
Documentation: ArgumentList ClarityMinor Issue: The README examples show Current: Import-Module dbatools.library -ArgumentList $trueRecommendation: Add a note explaining this syntax. Switch parameters passed via -ArgumentList require the positional value $true. This is standard PowerShell behavior but could benefit from a brief explanation in the docs for users unfamiliar with this pattern. |
Testing: No Automated TestsObservation: The commit messages mention adding integration tests to build.yml workflow, but I don't see test files in the diff. Recommendation: Consider adding tests that verify:
This would help ensure the feature works as expected and prevent future regressions, especially given the complexity of assembly loading across PowerShell editions. |
- Created test-avoidconflicts.ps1 with comprehensive test scenarios - Created test-avoidconflicts.yml workflow file - Tests validate default import, SqlServer module compatibility, and verbose logging - Workflow uses psmodulecache for efficient SqlServer module installation Co-authored-by: Chrissy LeMaire <potatoqualitee@users.noreply.github.com>
Pull Request Review - PR #34Thank you for this PR addressing issue #32! Here is my comprehensive review: ✅ StrengthsCode Quality
Documentation
🔍 Issues & Concerns1. Critical: Bug in Variable Scope (dbatools.library.psm1:122)Problem: The redirector variable is created inside a try-catch block (line 94), so it may not be available at line 122 if the try block fails. This could cause errors in Desktop PowerShell. Recommendation: Check if variable exists before using it: if ($PSVersionTable.PSEdition -ne "Core" -and (Get-Variable -Name redirector -ErrorAction SilentlyContinue)) {
[System.AppDomain]::CurrentDomain.remove_AssemblyResolve($redirector.EventHandler)
}2. Performance: Redundant Assembly List Processing (lines 177, 198)Problem: Inside the foreach loop, the assembly list is converted to string on each iteration when AvoidConflicts is enabled. This is inefficient. Recommendation: Build the assembly name string once before the loop to avoid repeated conversions. 3. Logic Issue: Duplicate Check (lines 207-208)Problem: Even when skipAssembly is false, there is still an "is it loaded" check on line 208. This is redundant. Recommendation: Simplify by using continue when skipping, eliminating the nested check. 4. Test Coverage: Missing Edge CasesThe test file does not cover:
5. Documentation: Missing Implementation DetailsREADME explains usage well but not what assemblies are checked. Users might wonder if it only checks SqlClient or all assemblies. 🔒 Security Considerations✅ No security concerns identified ⚡ Performance ConsiderationsEstimated impact: 30-70ms added to module load time with AvoidConflicts (acceptable but can be optimized) 📋 Test CoverageCurrent: Good coverage of basic scenarios 🎯 Recommendations PriorityHigh Priority (Fix Before Merge)
Medium Priority
📝 Overall Assessment
Recommendation: ✅ Approve with changes - The PR solves a real problem. Fix the critical redirector bug before merge. Great work! This feature will be valuable for users dealing with DLL conflicts. 🎉 |
Summary
Adds a
param()block todbatools.library.psm1that allows users to control which DLLs are loaded via the-ArgumentListparameter. This provides a flexible workaround for DLL conflicts with the SqlServer module.Changes
-SkipSqlClient,-SkipAzure,-SkipSmo, and-SkipAssembliesparametersUsage Example
Fixes #32
🤖 Generated with Claude Code