PowerShell / PowerShell/PSScriptAnalyzer

Cannot access a closed file

未關閉
#577 4 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

Issue - Discussion
主要語言
C#
星號
2.2k
分支
414
平均合併
13 小時 1 分鐘
30 天內合併 PR
2

描述

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

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

從堆疊追蹤中提到的 Microsoft.Windows.PowerShell.ScriptAnalyzer.Helper.GetModuleManifest 以及 MissingModuleManifestField 和 PSUseToExportFieldsInManifest 規則開始。使用所參照的 PesterHelpers.psd1 或另一個模組資訊清單重現 Invoke-ScriptAnalyzer,然後追蹤錯誤中顯示的 runspace 和 transcription 釋放過程。完成的標準是這些規則不再間歇性地回報 ObjectDisposedException。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
csharp, powershell
領域
devtools
Issue 類型
缺陷
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。