< 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@9d3a582b2d63930269564a7591aa77ef297cadeb
Line coverage
46%
Covered lines: 6
Uncovered lines: 7
Coverable lines: 13
Total lines: 41
Line coverage: 46.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

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#>
 11function Assert-KrAssemblyLoaded {
 12    [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '')]
 13    [CmdletBinding()]
 14    [OutputType([bool])]
 15    param (
 16        [Parameter(Mandatory = $true)]
 17        [string]$AssemblyPath
 18    )
 219    if (-not (Test-Path -Path $AssemblyPath -PathType Leaf)) {
 020        throw "Assembly not found at path: $AssemblyPath"
 21    }
 122    $assemblyName = [System.Reflection.AssemblyName]::GetAssemblyName($AssemblyPath).Name
 323    $loaded = [AppDomain]::CurrentDomain.GetAssemblies() | Where-Object { $_.GetName().Name -eq $assemblyName }
 124    if (-not $loaded) {
 025        if ($Verbose) {
 026            Write-Verbose "Loading assembly: $AssemblyPath"
 27        }
 28        try {
 029            Add-Type -LiteralPath $AssemblyPath
 30        } catch {
 031            Write-Error "Failed to load assembly: $AssemblyPath"
 032            return $false
 33        }
 34    } else {
 135        if ($Verbose) {
 036            Write-Verbose "Assembly already loaded: $AssemblyPath"
 37        }
 38    }
 139    return $true
 40}
 41

Methods/Properties

Assert-KrAssemblyLoaded()