GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — WriteObject enumerateCollection set to true not enumerating DataRowCollection in System.Data.DataTable · Issue #6453 · PowerShell/PowerShell

WriteObject enumerateCollection set to true not enumerating DataRowCollection in System.Data.DataTable #6453

New issue
Copy link
New issue
Copy link
Closed
#6511
Closed
WriteObject enumerateCollection set to true not enumerating DataRowCollection in System.Data.DataTable#6453
#6511
Copy link
Labels
Committee-ReviewedPS-Committee has reviewed this and made a decisionPS-Committee has reviewed this and made a decisionIssue-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 reclassifResolution-FixedThe issue is fixed.The issue is fixed.WG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtime

Description

@abhisheksinha89
Abhi (abhisheksinha89)
opened on Mar 21, 2018
Issue body actions

Steps to reproduce

Create a simple cmdlet with this method as the ProcessRecord()

protected override void ProcessRecord()
{
        DataTable dt = new DataTable("test");
        dt.Columns.Add("Name", typeof(string));
        dt.Columns.Add("Age", typeof(string));
        DataRow dr = dt.NewRow(); dr["Name"] = "John"; dr["Age"] = "20";
        DataRow dr2 = dt.NewRow(); dr["Name"] = "Susan"; dr["Age"] = "25";
        dt.Rows.Add(dr); dt.Rows.Add(dr2);
        WriteObject(dt, enumerateCollection: true);
}

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

> $PSVersionTable

Activity

  1. mklement0 commented on Mar 21, 2018

    @mklement0
    Michael Klement (mklement0)
    on Mar 21, 2018
    Contributor
    More actions

    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])

  2. BrucePay commented on Mar 21, 2018

    @BrucePay
    Bruce Payette (BrucePay)
    on Mar 21, 2018
    Collaborator
    More actions

    The issue is here in the code:

    PowerShell/src/System.Management.Automation/engine/LanguagePrimitives.cs

    Line 479 in 41b3161

    #if !CORECLR

    Enumerating DataTables is explicitly disabled .

    #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.

    Reacted by Michael Klement
  3. Bruce Payette (BrucePay)
    added
    WG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtime
    Issue-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 reclassif
    Review - CommitteeThe PR/Issue needs a review from the PowerShell CommitteeThe PR/Issue needs a review from the PowerShell Committee
    on Mar 21, 2018
  4. daxian-dbw commented on Mar 21, 2018

    @daxian-dbw
    Dongbo Wang (daxian-dbw)
    on Mar 21, 2018
    Member
    More actions

    I think the code was if/def'ed out originally when DataTable is not available in .NET Core.

  5. Steve Lee (SteveL-MSFT)
    added
    Committee-ReviewedPS-Committee has reviewed this and made a decisionPS-Committee has reviewed this and made a decision
    and removed
    Review - CommitteeThe PR/Issue needs a review from the PowerShell CommitteeThe PR/Issue needs a review from the PowerShell Committee
    on Mar 28, 2018
  6. SteveL-MSFT commented on Mar 28, 2018

    @SteveL-MSFT
    Steve Lee (SteveL-MSFT)
    on Mar 28, 2018
    Member
    More actions

    @PowerShell/powershell-committee reviewed this and it makes sense to have it consistent in that datarows are enumerated

  7. Aditya Patwardhan (adityapatwardhan)
    closed this as completedin #6511on Mar 29, 2018
  8. Ilya (iSazonov)
    added
    Resolution-FixedThe issue is fixed.The issue is fixed.
    on Mar 30, 2018
  9. Matteo-T commented on Oct 31, 2022

    @Matteo-T
    Matteo Taveggia (Matteo-T)
    on Oct 31, 2022
    More actions

    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 :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Committee-ReviewedPS-Committee has reviewed this and made a decisionPS-Committee has reviewed this and made a decisionIssue-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 reclassifResolution-FixedThe issue is fixed.The issue is fixed.WG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtime

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402520 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.