PowerShell / PowerShell/PSScriptAnalyzer

Cannot access a closed file

Aperta
#577 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Issue - Discussion
Lingua principale
C#
Stelle
2.2k
Fork
414
Merge medio
13h 1m
PR unite (30g)
2

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia da Microsoft.Windows.PowerShell.ScriptAnalyzer.Helper.GetModuleManifest e dalle regole MissingModuleManifestField e PSUseToExportFieldsInManifest indicate nello stack trace. Riproduci Invoke-ScriptAnalyzer con il PesterHelpers.psd1 indicato o con un altro manifesto del modulo, quindi traccia lo smaltimento del runspace e della trascrizione mostrato nell'errore. Il lavoro è completato quando queste regole non segnalano più in modo intermittente una ObjectDisposedException.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
csharp, powershell
Ambito
devtools
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.