PowerShell / PowerShell/PSScriptAnalyzer

Cannot access a closed file

Offen
#577 4 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Issue - Discussion
Vorherrschende Sprache
C#
Sterne
2.2k
Forks
414
Ø Merge
13 Std. 1 Min.
Gemergte PRs (30 T.)
2

Beschreibung

I'm occasionally getting this error on running Invoke-ScriptAnalyzer with v 1.6.0

Invoke-ScriptAnalyzer : Cannot access a closed file.

The Full Error Object is

writeErrorStream      : True
PSMessageDetails      : 
Exception             : System.ObjectDisposedException: Cannot access a closed file.
                           at System.IO.__Error.FileNotOpen()
                           at System.IO.FileStream.Flush(Boolean flushToDisk)
                           at System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder)
                           at System.Management.Automation.Host.TranscriptionOption.Dispose()
                           at System.Management.Automation.Host.PSHostUserInterface.StopAllTranscribing()
                           at System.Management.Automation.Runspaces.LocalRunspace.DoCloseHelper()
                           at System.Management.Automation.Runspaces.RunspaceBase.CoreClose(Boolean syncCall)
                           at System.Management.Automation.Runspaces.LocalRunspace.Close()
                           at System.Management.Automation.Runspaces.LocalRunspace.Dispose(Boolean disposing)
                           at System.Management.Automation.PowerShell.Dispose(Boolean disposing)
                           at Microsoft.Windows.PowerShell.ScriptAnalyzer.Helper.GetModuleManifest(String filePath, IEnumerable`1& errorRecord)
                           at Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.MissingModuleManifestField.<AnalyzeScript>d__0.MoveNext()
                           at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
                           at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
                           at Microsoft.Windows.PowerShell.ScriptAnalyzer.ScriptAnalyzer.<>c__DisplayClass63_0.<AnalyzeSyntaxTree>b__1()
TargetObject          : C:\Users\Ryan\Onedrive\Github\PowerShellModules\PesterHelpers\PesterHelpers.psd1
CategoryInfo          : InvalidOperation: (C:\Users\Ryan\O...terHelpers.psd1:String) [Invoke-ScriptAnalyzer], ObjectDisposedException
FullyQualifiedErrorId : RULE_ERROR,Microsoft.Windows.PowerShell.ScriptAnalyzer.Commands.InvokeScriptAnalyzerCommand
ErrorDetails          : 
InvocationInfo        : System.Management.Automation.InvocationInfo
ScriptStackTrace      : at <ScriptBlock>, C:\Users\Ryan\Onedrive\Github\PowerShellModules\PesterHelpers\PesterHelpers.tests.ps1: line 34
                        at Invoke-Test, C:\Program Files\WindowsPowerShell\Modules\Pester\3.4.0\Functions\It.ps1: line 253
                        at ItImpl, C:\Program Files\WindowsPowerShell\Modules\Pester\3.4.0\Functions\It.ps1: line 203
                        at It, C:\Program Files\WindowsPowerShell\Modules\Pester\3.4.0\Functions\It.ps1: line 117
                        at <ScriptBlock>, C:\Users\Ryan\Onedrive\Github\PowerShellModules\PesterHelpers\PesterHelpers.tests.ps1: line 33
                        at Describe, C:\Program Files\WindowsPowerShell\Modules\Pester\3.4.0\Functions\Describe.ps1: line 100
                        at <ScriptBlock>, C:\Users\Ryan\Onedrive\Github\PowerShellModules\PesterHelpers\PesterHelpers.tests.ps1: line 15
                        at <ScriptBlock>, C:\Program Files\WindowsPowerShell\Modules\Pester\3.4.0\Pester.psm1: line 279
                        at Invoke-Pester, C:\Program Files\WindowsPowerShell\Modules\Pester\3.4.0\Pester.psm1: line 292
                        at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {0, 1}

This seems only to fire occasionally on the following rules with the error message given above

PSUseToExportFieldsInManifest
PSMissingModuleManifestField

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginnen Sie mit Microsoft.Windows.PowerShell.ScriptAnalyzer.Helper.GetModuleManifest und den Regeln MissingModuleManifestField und PSUseToExportFieldsInManifest, die im Stacktrace genannt werden. Reproduzieren Sie Invoke-ScriptAnalyzer mit der referenzierten PesterHelpers.psd1 oder einem anderen Modulmanifest und verfolgen Sie anschließend die im Fehler angezeigte Freigabe von Runspace und Transkription. Die Arbeit ist abgeschlossen, wenn diese Regeln nicht mehr intermittierend eine ObjectDisposedException melden.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
csharp, powershell
Bereich
devtools
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.