Repository navigation
WriteObject enumerateCollection set to true not enumerating DataRowCollection in System.Data.DataTable #6453
Description
Activity
mklement0 commented
on Mar 21, 2018 ContributorMore actionsAt 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])The issue is here in the code:
#if !CORECLR
Enumerating DataTables is explicitly disabled .#if !CORECLR if (typeof(DataTable).IsAssignableFrom(objectType)) { return LanguagePrimitives.DataTableEnumerable; } #endifI 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.
Reacted by Michael Klement- addedWG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtimeIssue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifReview - CommitteeThe PR/Issue needs a review from the PowerShell CommitteeThe PR/Issue needs a review from the PowerShell Committee
on Mar 21, 2018 I think the code was if/def'ed out originally when
DataTableis not available in .NET Core.- addedCommittee-ReviewedPS-Committee has reviewed this and made a decisionPS-Committee has reviewed this and made a decisionand removedReview - CommitteeThe PR/Issue needs a review from the PowerShell CommitteeThe PR/Issue needs a review from the PowerShell Committee
on Mar 28, 2018 @PowerShell/powershell-committee reviewed this and it makes sense to have it consistent in that datarows are enumerated
FWIW, there is a typo in Abhi (@abhisheksinha89)'s repro:
// ... DataRow dr2 = dt.NewRow(); dr2["Name"] = "Susan"; dr2["Age"] = "25"; // dr2, instead of dr! // ...
which would make it look like this was not fixed :-)
Steps to reproduce
Create a simple cmdlet with this method as the ProcessRecord()
Expected behavior
Return type should be a System.Array with the 2 rows enumerated.
(This works on Powershell 5 with the full .NET Framework)
Actual behavior
Return type is a DataTable not a System.Array with the rows enumerated.
Environment data