Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 28, 2025

Changes proposed in this pull request

  • Fixed missing comma separator in CSV export after Bytes field causing malformed output (header: BytesPortStatusBytes,PortStatus)
  • Added null checks for PingInfo, Ports, and NetBIOSInfo properties to prevent NullReferenceException across all export formats (CSV, XML, JSON)
  • Optimized JSON and XML exports: use Array.Empty<object>() and Enumerable.Empty<XElement>() instead of allocating empty arrays or returning null

Related issue(s)

Copilot generated summary

Copilot summary

The export methods in ExportManager.IPScannerHostInfo.cs were failing with NullReferenceException when encountering scan results with null collections or properties. The CSV export also had a formatting bug where the Bytes field lacked a comma separator, causing column misalignment.

CSV Export (CreateCsv):

// Before: Missing comma after Bytes
$"{info.PingInfo.Bytes}" + $"{(info.IsAnyPortOpen ? ...)}"

// After: Comma added, null checks applied
if (info?.PingInfo == null) continue;
if (info.Ports != null) { /* iterate ports */ }
$"{info.PingInfo.Bytes}," + $"{(info.IsAnyPortOpen ? ...)}"
$"{info.NetBIOSInfo?.IsReachable},"  // Null-conditional operators

XML Export (CreateXml):

// Before: No null filtering or handling
from info in collection select new XElement(...)
from port in info.Ports select ...  // NullReferenceException if Ports is null

// After: Filter nulls, return empty enumerable
from info in collection
where info?.PingInfo != null
select new XElement(...,
    info.Ports != null 
        ? from port in info.Ports select ...
        : Enumerable.Empty<XElement>()
)

JSON Export (CreateJson):

// Before: No filtering, inefficient array allocation
var jsonData = new object[collection.Count];
var jsonDataPorts = new object[collection[i].Ports.Count];  // Throws if Ports is null

// After: Pre-filter, conditional allocation
var validCollection = collection.Where(info => info?.PingInfo != null).ToList();
object[] jsonDataPorts = info.Ports != null && info.Ports.Count > 0
    ? new object[info.Ports.Count]
    : Array.Empty<object>();

All export methods now handle null properties defensively while maintaining data integrity.

To-Do

Contributing

By submitting this pull request, I confirm the following:

Original prompt

Can you check this issue #2951 and find possible issues in the logic.

I assume it's in the following files:

https://github.com/BornToBeRoot/NETworkManager/blob/main/Source/NETworkManager.Models/Export/ExportManager.IPScannerHostInfo.cs

https://github.com/BornToBeRoot/NETworkManager/blob/main/Source/NETworkManager/ViewModels/IPScannerViewModel.cs


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits December 28, 2025 14:29
Co-authored-by: BornToBeRoot <16019165+BornToBeRoot@users.noreply.github.com>
Co-authored-by: BornToBeRoot <16019165+BornToBeRoot@users.noreply.github.com>
Co-authored-by: BornToBeRoot <16019165+BornToBeRoot@users.noreply.github.com>
Copilot AI changed the title [WIP] Analyze logic issues in IPScannerHostInfo and IPScannerViewModel Fix IP scanner export NullReferenceException and CSV format bug Dec 28, 2025
Copilot AI requested a review from BornToBeRoot December 28, 2025 14:35
@BornToBeRoot BornToBeRoot marked this pull request as ready for review December 28, 2025 14:49
@BornToBeRoot BornToBeRoot added this to the next-release milestone Dec 28, 2025
@mergify mergify bot merged commit 9d98785 into main Dec 28, 2025
4 checks passed
@mergify mergify bot deleted the copilot/check-issues-in-logic branch December 28, 2025 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ip scanner can't export to file

2 participants