WriteObject and WriteError methods cannot be called from outside the overrides
See original GitHub issueSince months I’ve been ignoring this error but I decided to ask, maybe it’s something that can be addressed.
Basically my script copies all files .ps1 content, merges them into single psm1, saves it in Temp folder and executes formatter:
[-] Format-Code - Formatting on file C:\Users\przemyslaw.klys\AppData\Local\Temp\PSSharedGoods\PSSharedGoods.psm1 failed. Error: The WriteObject and WriteError methods cannot be called from outside the overrides of the BeginProcessing, ProcessRecord, and EndProcessing methods, and they can only be called from within the same thread. Validate that the cmdlet makes these calls correctly, or contact Microsoft Customer Support Services.
FormatterSettings = @{
IncludeRules = @(
'PSPlaceOpenBrace',
'PSPlaceCloseBrace',
'PSUseConsistentWhitespace',
'PSUseConsistentIndentation',
'PSAlignAssignmentStatement',
'PSUseCorrectCasing'
)
Rules = @{
PSPlaceOpenBrace = @{
Enable = $true
OnSameLine = $true
NewLineAfter = $true
IgnoreOneLineBlock = $true
}
PSPlaceCloseBrace = @{
Enable = $true
NewLineAfter = $false
IgnoreOneLineBlock = $true
NoEmptyLineBefore = $false
}
PSUseConsistentIndentation = @{
Enable = $true
Kind = 'space'
PipelineIndentation = 'IncreaseIndentationAfterEveryPipeline'
IndentationSize = 4
}
PSUseConsistentWhitespace = @{
Enable = $true
CheckInnerBrace = $true
CheckOpenBrace = $true
CheckOpenParen = $true
CheckOperator = $true
CheckPipe = $true
CheckSeparator = $true
}
PSAlignAssignmentStatement = @{
Enable = $true
CheckHashtable = $true
}
PSUseCorrectCasing = @{
Enable = $true
}
}
}
If an unexpected error was thrown then please report the full error details using e.g. $error[0] | Select-Object *
PSMessageDetails :
Exception : System.Management.Automation.PSInvalidOperationException: The WriteObject and WriteError methods cannot be called from
outside the overrides of the BeginProcessing, ProcessRecord, and EndProcessing methods, and they can only be called fro
m within the same thread. Validate that the cmdlet makes these calls correctly, or contact Microsoft Customer Support S
ervices.
at System.Management.Automation.MshCommandRuntime.ThrowIfWriteNotPermitted(Boolean needsToWriteToPipeline)
at System.Management.Automation.MshCommandRuntime.WriteHelper_ShouldWrite(ActionPreference preference, ContinueStatu
s lastContinueStatus)
at System.Management.Automation.MshCommandRuntime.WriteVerbose(VerboseRecord record, Boolean overrideInquire)
at System.Management.Automation.Cmdlet.WriteVerbose(String text)
at Microsoft.Windows.PowerShell.ScriptAnalyzer.ScriptAnalyzer.AnalyzeSyntaxTree(ScriptBlockAst scriptAst, Token[] sc
riptTokens, String filePath, Boolean skipVariableAnalysis)
at Microsoft.Windows.PowerShell.ScriptAnalyzer.ScriptAnalyzer.AnalyzeScriptDefinition(String scriptDefinition, Scrip
tBlockAst& scriptAst, Token[]& scriptTokens, Boolean skipVariableAnalysis)
at Microsoft.Windows.PowerShell.ScriptAnalyzer.ScriptAnalyzer.Fix(EditableText text, Range range, Boolean skipParsin
g, Range& updatedRange, Boolean& fixesWereApplied, ScriptBlockAst& scriptAst, Token[]& scriptTokens, Boolean skipVariab
leAnalysis)
at Microsoft.Windows.PowerShell.ScriptAnalyzer.Formatter.Format[TCmdlet](String scriptDefinition, Settings settings,
Range range, TCmdlet cmdlet)
at Microsoft.Windows.PowerShell.ScriptAnalyzer.Commands.InvokeFormatterCommand.ProcessRecord()
at System.Management.Automation.CommandProcessor.ProcessRecord()
TargetObject :
CategoryInfo : InvalidOperation: (:) [Invoke-Formatter], PSInvalidOperationException
FullyQualifiedErrorId : InvalidOperation,Microsoft.Windows.PowerShell.ScriptAnalyzer.Commands.InvokeFormatterCommand
ErrorDetails :
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace : at <ScriptBlock>, C:\Support\GitHub\PSPublishModule\Private\Format-Code.ps1: line 24
at Write-TextWithTime, C:\Support\GitHub\PSPublishModule\Private\Write-TextWithTime.ps1: line 15
at Format-Code, C:\Support\GitHub\PSPublishModule\Private\Format-Code.ps1: line 21
at Merge-Module, C:\Support\GitHub\PSPublishModule\Private\Merge-Module.ps1: line 256
at Start-ModuleBuilding, C:\Support\GitHub\PSPublishModule\Private\Start-ModuleBuilding.ps1: line 258
at New-PrepareModule, C:\Support\GitHub\PSPublishModule\Public\New-PrepareModule.ps1: line 18
at <ScriptBlock>, C:\Support\GitHub\PSSharedGoods\Publish\Manage-PSSharedGoods.ps1: line 153
This error shows up usually (but not always) if during the script run I do some “actions” within VSCode. Basically I run the script to “build my module” and then I continue edits in code for README or some fixes within ps1 files which shouldn’t affect the formatting because I don’t touch PSM1 file in the temp folder. But maybe some conflicts happen because of me using it?
Environment data
> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.19041.1
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.19041.1
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.19.0
1.19.0
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
ThreadJob: The WriteObject and WriteError cannot be called ...
The WriteObject and WriteError methods cannot be called from outside the overrides of the BeginProcessing, ProcessRecord, and EndProcessing ...
Read more >"The WriteObject and WriteError methods cannot be called ...
Error : "The WriteObject and WriteError methods cannot be called from outside the overrides of the BeginProcessing, ProcessRecord, ...
Read more >The WriteObject and WriteError methods error
The WriteObject and WriteError methods cannot be called from outside the overrides of the BeginProcessing, ProcessRecord, and EndProcessing ...
Read more >Support For Nested invoke-sqlcmd - TechNet - Microsoft
PSInvalidOperationException. ,. The WriteObject. and WriteError methods cannot be called from outside the overrides of the BeginProcessing,.
Read more >PnPPoweShell-WriteObject/WriteError methods cannot be called
Get-PnPFile : The WriteObject and WriteError methods cannot be called from outside the overrides of the BeginProcessing, ProcessRecord, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Working on several things at once at the moment, but may be able to look at a more targeted bugfix to lessen the impact here.
The other work is much larger, likely multi-month timeline. As always when people ask for ETAs in issues, all I know is what I’ve seen so far. I’ve spent about two weeks on the PSES problem and the hard part is still to come. Making PSSA work better is going to take months, since it’s basically being rewritten so that it can be safely hosted.
I don’t think new version worked tho in terms of PDB