< Summary - Kestrun — Combined Coverage

Information
Class: Private.Assembly.Assert-KrAssemblyLoaded
Assembly: Kestrun.PowerShell.Private
File(s): /home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Private/Assembly/Assert-KrAssemblyLoaded.ps1
Tag: Kestrun/Kestrun@5f1d2b981c9d7292c11fd448428c6ab6c811c5de
Line coverage
63%
Covered lines: 12
Uncovered lines: 7
Coverable lines: 19
Total lines: 59
Line coverage: 63.1%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 11/19/2025 - 17:40:50 Line coverage: 0% (0/14) Total lines: 42 Tag: Kestrun/Kestrun@fcf33342333cef0516fe0d0912a86709874fd02612/21/2025 - 19:25:34 Line coverage: 0% (0/19) Total lines: 59 Tag: Kestrun/Kestrun@63eee3e6ff7662a7eb5bb3603d667daccb809f2d01/21/2026 - 17:07:46 Line coverage: 63.1% (12/19) Total lines: 59 Tag: Kestrun/Kestrun@3f6f61710c7ef7d5953cab578fe699c1e5e01a3602/05/2026 - 00:28:18 Line coverage: 0% (0/19) Total lines: 59 Tag: Kestrun/Kestrun@d9261bd752e45afa789d10bc0c82b7d5724d958904/04/2026 - 18:57:31 Line coverage: 63.1% (12/19) Total lines: 59 Tag: Kestrun/Kestrun@25c95cfbd84df534a61ed03b9abab034ac673a75

Coverage delta

Coverage delta 64 -64

Metrics

File(s)

/home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Private/Assembly/Assert-KrAssemblyLoaded.ps1

#LineLine coverage
 1<#
 2    .SYNOPSIS
 3        Ensures that a .NET assembly is loaded only once.
 4
 5    .DESCRIPTION
 6        Checks the currently loaded assemblies for the specified path. If the
 7        assembly has not been loaded yet, it is added to the current AppDomain.
 8    .PARAMETER AssemblyPath
 9        Path to the assembly file to load.
 10    .PARAMETER LoadContext
 11        The AssemblyLoadContext to load the assembly into. Default is the Default context.
 12        This helps avoid issues with multiple contexts loading the same assembly.
 13    .OUTPUTS
 14        [bool] - True if the assembly is loaded successfully or already loaded, false otherwise.
 15#>
 16function Assert-KrAssemblyLoaded {
 17    [CmdletBinding()]
 18    [OutputType([bool])]
 19    param(
 20        [Parameter(Mandatory)]
 21        [string]$AssemblyPath,
 22
 23        # Default = require it to be loadable from the Default ALC (fixes VSCode/PSES split-load issue)
 24        [System.Runtime.Loader.AssemblyLoadContext]$LoadContext = [System.Runtime.Loader.AssemblyLoadContext]::Default
 25    )
 26
 227    if (-not (Test-Path -LiteralPath $AssemblyPath -PathType Leaf)) {
 028        throw "Assembly not found at path: $AssemblyPath"
 29    }
 30
 231    $full = (Resolve-Path -LiteralPath $AssemblyPath).Path
 132    $asmName = [System.Reflection.AssemblyName]::GetAssemblyName($full)
 33
 34    # Find an already-loaded assembly with same simple name *in the desired ALC*
 135    $loadedInContext = [AppDomain]::CurrentDomain.GetAssemblies() |
 136        Where-Object {
 137            $_.GetName().Name -eq $asmName.Name -and
 138            ([System.Runtime.Loader.AssemblyLoadContext]::GetLoadContext($_) -eq $LoadContext)
 39        } |
 140        Select-Object -First 1
 41
 142    if ($loadedInContext) {
 243        Write-Verbose ('Assembly already loaded in {0} ALC: {1} {2} from {3}' -f `
 144            ($LoadContext.Name ?? 'Default'), $loadedInContext.GetName().Name, $loadedInContext.GetName().Version, $load
 145        return $true
 46    }
 47
 048    Write-Verbose ('Loading assembly into {0} ALC: {1}' -f ($LoadContext.Name ?? 'Default'), $full)
 49
 50    try {
 51        # Load into the requested context (Default by default)
 052        [void]$LoadContext.LoadFromAssemblyPath($full)
 053        return $true
 54    } catch {
 055        Write-Error "Failed to load assembly: $full"
 056        Write-Error $_
 057        return $false
 58    }
 59}

Methods/Properties

Assert-KrAssemblyLoaded()