Skip to content

Cannot extract archives if a variable named srcStream exists #141

@bematteo

Description

@bematteo

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest version
  • Search the existing issues.

Steps to reproduce

I had a string variable named $srcStream declared before calling Expand-Archive, because of that I was getting this error:

Method invocation failed because [System.String] does not contain a method named 'Dispose'.

The problematic code is in Microsoft.PowerShell.Archive.psm1, where $srcStream gets disposed.

To reproduce:

$srcStream = "whatever"
Expand-Archive -Path "arc.zip"

Expected behavior

Archive gets extracted

Actual behavior

Extraction fails

Error details

Method invocation failed because [System.String] does not contain a method named 'Dispose'.
At C:\windows\system32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.Archive\Microsoft.PowerShell.Archive.psm1:1077 char:25
+                         $srcStream.Dispose()
+                         ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

Environment data

Name                           Value
----                           -----
PSVersion                      7.2.3
PSEdition                      Core
GitCommitId                    7.2.3
OS                             Microsoft Windows 10.0.19042
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Version

7.2.3

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions