PowerShell / Microsoft.PowerShell.Archive

Archive PowerShell module contains cmdlets for working with ZIP archives
https://technet.microsoft.com/en-us/library/dn818910.aspx
MIT License
94 stars 37 forks source link

Cannot extract archives if a variable named srcStream exists #141

Closed bematteo closed 2 years ago

bematteo commented 2 years ago

Prerequisites

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

ayousuf23 commented 2 years ago

This is solved in version 2 preview.

bematteo commented 2 years ago

I see, I will close this then.