Skip to content
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

Avoid benign GAC warnings logged by install/uninstall #1984

Closed
pjanotti opened this issue Jan 12, 2023 · 3 comments · Fixed by #2171
Closed

Avoid benign GAC warnings logged by install/uninstall #1984

pjanotti opened this issue Jan 12, 2023 · 3 comments · Fixed by #2171
Assignees
Milestone

Comments

@pjanotti
Copy link
Contributor

Running the PowerShell install/uninstall ends up logging warning events to the Windows Event Logger that are benign and not actionable by the user:

image

This issue is a follow-up to #1906

@pjanotti pjanotti changed the title Avoid benign GAC warnings logged by install/remove Avoid benign GAC warnings logged by install/uninstall Jan 12, 2023
@pjanotti pjanotti assigned pjanotti and pellared and unassigned pellared and pjanotti Jan 18, 2023
@pjanotti pjanotti added this to the 0.5.1 milestone Jan 18, 2023
@pellared
Copy link
Member

Do you have any preference on how to implement it?
I see two possibilities:

  1. Use https://learn.microsoft.com/en-us/dotnet/standard/assembly/identify#using-the-pereader-class.

    Pros:

    • should not require a lot of maintenance in future

    Cons:

  2. Have a "exclude list" which would currently be the 3 assemblies.

    Pros:

    • no dependencies and possibly best performance

    Cons:

    • would require more maintaince (updating the exclude list)

We could consider also writing a PowerShell unit test to check if after using the module there are no new errors or warnings in the Windows Event Log.

@rajkumar-rangaraj
Copy link
Contributor

It's worth exploring option 1, at a different it could help in different places too.

@pellared
Copy link
Member

pellared commented Feb 6, 2023

I spend a few hours trying the option 1, but there are too many obstacles to make it worth in my opinion. Example problems:

Notable article: https://endjin.com/blog/2020/12/how-to-consume-a-nuget-package-in-powershell Maybe someone else would have more luck...

Ported C# snippet to PowerShell (not tested):

function Test-Assembly([string] $Path) {
    try {
        $fs = [System.IO.FileStream]::new($Path, [System.IO.FileMode.Open], [System.IO.FileAccess.Read], [System.IO.FileShare.ReadWrite])

        # Try to read CLI metadata from the PE file.
        $peReader = [System.Reflection.PortableExecutable.PEReader]::new($fs)

        if (-not $peReader.HasMetadata) {
            return $false # File does not have CLI metadata.
        }

        # Check that file has an assembly manifest.
        $reader = $peReader.GetMetadataReader()
        return $reader.IsAssembly
    }
    finally {
        if ($null -ne $fs) {
            $fs.Dispose()
        }
        if ($null -ne $peReader) {
            $fs.Dispose()
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

3 participants