BornToBeRoot/NETworkManager · error · Exception
message (joined PowerShell error streams)
Error message
message (joined PowerShell error streams)
What it means
ThrowOnError inspects ps.Streams.Error after running NetNeighbor PowerShell commands (New-/Remove-NetNeighbor, or clearing the table). If any error records exist, they are joined with Environment.NewLine, logged as a warning, and thrown as a generic Exception carrying the full PowerShell error text.
Solutions
- Run the application elevated; NetNeighbor cmdlets require administrator rights.
- Validate the IP address and physical (MAC) address format before calling AddEntryAsync.
- For deletes, check the entry exists first or tolerate 'not found' errors by parsing the message.
- Catch the exception and show the multi-line PowerShell error to the user; it names the failing cmdlet and parameter.
Example fix
// before
await NeighborTable.AddEntryAsync(new NeighborTableEntryInfo { IPAddress = ip, PhysicalAddress = mac, ... }); // throws on bad input
// after
if (!System.Net.IPAddress.TryParse(ip, out _) || !System.Net.NetworkInformation.PhysicalAddress.Parse(mac.Replace('-', ':'))...)
throw new ArgumentException("Invalid IP or MAC address");
await NeighborTable.AddEntryAsync(entry); Defensive patterns
Strategy: validation
Validate before calling
null
Type guard
static bool IsValidNeighborEntry(NeighborTableEntryInfo e) => e != null && e.IPAddress != null && e.PhysicalAddress != null && !e.PhysicalAddress.Equals(System.Net.NetworkInformation.PhysicalAddress.None) && e.InterfaceIndex > 0;
Try / catch
try
{
await NeighborTable.AddEntryAsync(entry);
}
catch (Exception ex) when (ex.Message.Contains("already exists") || ex.Message.Contains("Failed"))
{
Log.Warn($"NetNeighbor error: {ex.Message}");
// show the multi-line PowerShell error to the user
} Prevention
- Run elevated; NetNeighbor cmdlets require administrator rights.
- Validate IP/MAC/interface index before calling Add/Delete.
- Treat duplicate-entry errors as recoverable; parse the message rather than assuming a hard failure.
When it happens
Trigger: AddEntryAsync with an invalid IP/MAC or an entry already present; DeleteEntryAsync for a neighbor that does not exist; DeleteTableAsync when entries cannot be removed (in-use or permission issues); running without elevation so NetNeighbor cmdlets are denied.
Common situations: Non-admin execution (NetNeighbor requires elevation); duplicate static ARP entries; malformed MAC address strings; interface index/IPAddress not matching an existing interface.
Related errors
- Win32Exception for native error code (int)result
- string.Join("; ", ps.Streams.Error.Select(e =>…
- string.Join("; ", ps.Streams.Error)
- Error while retrieving TCP table
- Could not load PSDiscoveryProtocol.psm1
AI-assisted analysis of BornToBeRoot/NETworkManager@2780d65469 (2026-09-12).
Data as JSON: /api/errors/21e2c5e11f61939c.
Report an issue: GitHub.
Appendix: source
Thrown at Source/NETworkManager.Models/Network/NeighborTable.cs:407
{
RunspaceLock.Release();
}
}
/// <summary>
/// Throws an <see cref="Exception"/> whose message is the joined PowerShell error
/// stream when <paramref name="ps"/> reported one or more errors.
/// </summary>
private static void ThrowOnError(SMA.PowerShell ps)
{
if (ps.Streams.Error.Count == 0)
return;
var message = string.Join(Environment.NewLine, ps.Streams.Error);
Log.Warn($"PowerShell error: {message}");
throw new Exception(message);
}
#endregion
}
View on GitHub (pinned to 2780d65469)