Skip to content

[release/v7.5] Handle null reference exception in CsvCommands.cs: ConvertPSObjectToCSV#26394

Closed
TravisEz13 wants to merge 1 commit into
PowerShell:release/v7.5from
TravisEz13:backport/release/v7.5/pr/26144
Closed

[release/v7.5] Handle null reference exception in CsvCommands.cs: ConvertPSObjectToCSV#26394
TravisEz13 wants to merge 1 commit into
PowerShell:release/v7.5from
TravisEz13:backport/release/v7.5/pr/26144

Conversation

@TravisEz13

@TravisEz13 TravisEz13 commented Nov 5, 2025

Copy link
Copy Markdown
Member

Backport of #26144 to release/v7.5

Triggered by @TravisEz13 on behalf of @mikkas456

Original CL Label: CL-General

/cc @PowerShell/powershell-maintainers

Impact

Customer Impact

  • Found internally

This PR backports a fix for a null reference exception in CSV commands. The original PR addresses a bug where ConvertPSObjectToCSV would throw a null reference exception when processing certain objects. This improves reliability and prevents crashes when working with CSV data.

Regression

  • Yes
  • No

This is a bug fix, not a regression fix.

Testing

The original PR included test cases to verify the null reference handling. The fix was validated through unit tests that cover the edge case scenarios. The backport maintains the same test coverage.

Risk

  • High
  • Medium
  • Low

This is a targeted bug fix with a narrow scope. The change only affects error handling in the CSV conversion logic and includes test coverage. The risk is low as it prevents exceptions without changing the core functionality of CSV commands.

Copilot AI review requested due to automatic review settings November 5, 2025 20:19
@TravisEz13 TravisEz13 added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Nov 5, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a NullReferenceException when exporting hashtables with null property values to CSV format. The fix adds a null-conditional operator to safely handle null dictionary values.

  • Adds null-conditional operator (?.) when calling ToString() on dictionary values
  • Adds test coverage for exporting hashtables and PSCustomObjects with null values
  • Verifies that the CSV export correctly represents null values as empty fields

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/Microsoft.PowerShell.Commands.Utility/commands/utility/CsvCommands.cs Adds null-conditional operator to prevent NullReferenceException when dictionary contains null values
test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Csv.Tests.ps1 Adds tests to verify Export-Csv handles null values in hashtables correctly
test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Csv.Tests.ps1 Adds test for ConvertTo-Csv with hashtable containing null values

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@microsoft-github-policy-service microsoft-github-policy-service Bot added the Review - Needed The PR is being reviewed label Nov 13, 2025
@microsoft-github-policy-service

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

@TravisEz13

Copy link
Copy Markdown
Member Author

I don't think this meets the bar to go back to 7.5 as it was not a regression.

@theznerd

Copy link
Copy Markdown

@TravisEz13 - I recognize that we're imminently close to v7.6 release, but it is still preview. Is the "bar" documented somewhere? Not intending to be rude - just for my edification.

@daxian-dbw

daxian-dbw commented Feb 11, 2026

Copy link
Copy Markdown
Member

Given this is not a regression in v7.5, we are not going to backport it to v7.5 release branch. So, closing the PR.
It turns out the original fix didn't make into v7.6-rc. I'm not sure if we should re-consider the decision to backport it to 7.5 and even 7.6, so I will leave this one open for the next triage meeting.

@daxian-dbw daxian-dbw closed this Feb 11, 2026
@daxian-dbw daxian-dbw reopened this Feb 11, 2026
@theznerd

Copy link
Copy Markdown

@daxian-dbw - is the decision-making process here for what is backported or not documented somewhere? Or is it simply "if we didn't break it, we won't fix it until a future release" (e.g. no regression)? I know of at least one person experiencing this annoyance in 7.5, and if it's true it didn't make 7.6-rc, that's disappointing as well.

@daxian-dbw

daxian-dbw commented Feb 12, 2026

Copy link
Copy Markdown
Member

I don't think it's documented anywhere, but the bar is high -- usually only regressions in that particular release or security fixes.
But I do see that if we don't do the backport, the fix will only be available in 7.7, which is still one year out, which is frustrating, and that's why I left this PR open for the next backport triage.

@daxian-dbw

Copy link
Copy Markdown
Member

Closing this PR, but leave the original PR #26144 labelled as Backport-7.5.x-Consider.

@daxian-dbw daxian-dbw closed this Apr 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log Review - Needed The PR is being reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants