The WriteObject and WriteError methods error

Hi All / @adam -

Has anyone seen this error before? I usually get this in UDgrid and UDtable, only for one specific page - others are fine. Iam using UDv2.9.

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.

Can you share some of your code? I’ve never seen this before.

This is one sample code - it normally happen after a page reload or table/ grid refresh, its gone after another round of refresh or reload. Basically, in the same page, I have a couple of tables with similar build where it gets data from DB then pass to psCustomObj - all tables are in their own coumn endpoint.

On another page. Today I added another table under UDTabContainer and it has auto refresh, after a couple of table refresh I am now seeing the error as well as some “split” error on the next refresh. The issue never happen when it only had one table.

I am not able to replicate this successfully. But looking at the issues online, it seems perhaps the table or table invoke DB are fighting for write resources?

New-UDRow {
            New-UDColumn -Size 1 {}
            New-UDColumn -Id "xxx" -Size 10 -Endpoint {
                New-UDGrid -Id "xxxx" -NoExport -PageSize 100 -FilterText "Search INC#" -Headers @("Region", "INC #", "Rpt Lvl", "Short Description", "Impacted Service", "Closure Code", "Root Cause Service", "Opened At", "Resolved At", "Category L1", "Category L2", "Outage Duration") -Properties @("REGION", "INC_NO", "REPORTING_LVL", "SHORT_DESC", "IMPACTED_SVC", "CLOSURE_CD", "CAUSE_SVC", "OPENED_AT", "RESOLVED_AT", "CAT_LVL_1", "CAT_LVL_2", "OUTAGE_DURATION") -Endpoint {
                   
                    $csv_all = Invoke-Sqlcmd -ServerInstance "xxxxx" -Query $all_query -Username "xxxx" -Password "xxxx"
                    
                    $csv_all | ForEach-Object {

                        if ($_.IMPACTED_SVC -eq "xxxx") {
                            $region = "AP"
                        }
                        elseif ($_.IMPACTED_SVC -eq "xxxxx") {
                            $region = "AM + US"
                        }
                        elseif ($_.IMPACTED_SVC -eq "xxxxxx") {
                            $region = "EMEA"
                        }
                        elseif ($_.IMPACTED_SVC -eq "xxxxx") {
                            $region = "GLOBAL"
                        }

                        $outage_duration = $outage_mins = $outage_hrs = $null

                        if ($_.outage_start -notlike "*1900*" -and $_.outage_end -notlike "*1900*" ) {
                            $outage_mins = [int](New-TimeSpan $_.outage_start  $_.outage_end).Minutes
                            $outage_hrs = [int](New-TimeSpan $_.outage_start  $_.outage_end).Hours
                            $outage_duration = "$outage_hrs hr $outage_mins mins"
                        }

                        [PSCustomObject]@{
                            REGION          = $region
                            INC_NO          = New-UDLink -Text "$($_.INC_NO)" -Url "xxxxx" -OpenInNewWindow $true
                            INC_STATE       = $_.INC_STATE
                            REPORTING_LVL   = $_.REPORTING_LVL
                            SHORT_DESC      = $_.SHORT_DESC
                            IMPACTED_SVC    = $_.IMPACTED_SVC
                            CAT_LVL_1       = $_.CAT_LVL_1
                            CAT_LVL_2       = $_.CAT_LVL_2
                            CAUSE_SVC       = $_.CAUSE_SVC
                            CLOSURE_CD      = $_.CLOSURE_CD
                            OPENED_AT       = ([datetime]$_.OPENED_AT).ToString("dd-MMM-yyyy HH:mm:ss").ToUpper()
                            RESOLVED_AT     = ([datetime]$_.RESOLVED_AT).ToString("dd-MMM-yyyy HH:mm:ss").ToUpper()
                            OUTAGE_DURATION = $outage_duration
                        }
                    } | Out-UDGridData
                }                
            }
            New-UDColumn -Size 1 {}

It seems to be related with Invoke-Sqlcmd.