You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
WriteObject enumerateCollection set to true not enumerating DataRowCollection in System.Data.DataTable #6453
At least at first glance the current behavior makes more sense, given that [System.Data.DataTable] does not implement the [System.Collections.IEnumerable] interface and PowerShell therefore doesn't consider it a collection.
That the behavior changed is definitely disconcerting, however, and I hope someone else can shed light on this.
Using WriteObject(dt.Rows, enumerateCollection: true) instead fixes the problem (because the type of .Rows is [System.Data.DataRowCollection], which does implement [IEnumerable])
#if !CORECLR
if (typeof(DataTable).IsAssignableFrom(objectType))
{
return LanguagePrimitives.DataTableEnumerable;
}
#endif
I don't know why this was done or if there is any reason not to turn it back on (other than it's a breaking change from 6.0). I've marked it for review by the committee.
Activity
mklement0 commentedon Mar 21, 2018
At least at first glance the current behavior makes more sense, given that
[System.Data.DataTable]does not implement the[System.Collections.IEnumerable]interface and PowerShell therefore doesn't consider it a collection.That the behavior changed is definitely disconcerting, however, and I hope someone else can shed light on this.
Using
WriteObject(dt.Rows, enumerateCollection: true)instead fixes the problem (because the type of.Rowsis[System.Data.DataRowCollection], which does implement[IEnumerable])BrucePay commentedon Mar 21, 2018
The issue is here in the code:
PowerShell/src/System.Management.Automation/engine/LanguagePrimitives.cs
Line 479 in 41b3161
Enumerating DataTables is explicitly disabled .
I don't know why this was done or if there is any reason not to turn it back on (other than it's a breaking change from 6.0). I've marked it for review by the committee.
daxian-dbw commentedon Mar 21, 2018
I think the code was if/def'ed out originally when
DataTableis not available in .NET Core.SteveL-MSFT commentedon Mar 28, 2018
@PowerShell/powershell-committee reviewed this and it makes sense to have it consistent in that datarows are enumerated
Matteo-T commentedon Oct 31, 2022
FWIW, there is a typo in Abhi (@abhisheksinha89)'s repro:
which would make it look like this was not fixed :-)