You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
IPv6 System.Net.HttpListenerException (400): Invalid port in prefix. #34399
works fine on Windows but fails on linux-x64 (WSL, Ubuntu)
exception: System.Net.HttpListenerException (400): Invalid port in prefix.
at System.Net.HttpEndPointManager.AddPrefixInternal(String p, HttpListener listener)
at System.Net.HttpEndPointManager.AddListener(HttpListener listener)
at System.Net.HttpListener.Start()
Additionally the behavior in regards of IPv4 IPv6 on Windows and Linux is different. With the prefix: http://localhost:54321/meow/
HttpListener binds both to IPv4 and IPv6 on Windows. But not on Linux.
works fine on Windows but fails on linux-x64 (WSL, Ubuntu)
FYI, the implementation of HttpListener on Linux is substantially different than Windows. Windows uses the original .NET Framework (ported to .NET Core) implemented layered on top of http.sys. Linux uses a separate implementation originally from Mono.
Similar issue here, works fine in Windows 11 (.net 6.0.401) but fails in Raspberry Pi OS (linux-arm 6.0.401) System.Net.HttpListenerException (400): Invalid path.
The issue here is a clear bug in the .NET code under src/System/Net/Managed/HttpEndPointManager.cs in AddPrefixInternal. This method is used for all HttpListener prefixes on non-Windows hosts and uses very basic string parsing which isn't capable of handling IPv6 addresses in any form due to simply treating the first : character as the beginning of the port, which obviously doesn't work for IPv6 addresses which contain : characters.
Activity
davidsh commentedon Apr 1, 2020
FYI, the implementation of HttpListener on Linux is substantially different than Windows. Windows uses the original .NET Framework (ported to .NET Core) implemented layered on top of http.sys. Linux uses a separate implementation originally from Mono.
josemoliver commentedon Sep 21, 2022
Similar issue here, works fine in Windows 11 (.net 6.0.401) but fails in Raspberry Pi OS (linux-arm 6.0.401)
System.Net.HttpListenerException (400): Invalid path.
listener.Prefixes.Add("http://*:"+port+"/"+path);https://github.com/josemoliver/WeatherServer/blob/main/Program.cs
shapea commentedon Feb 19, 2025
This was reported nearly 5 years ago?
The issue here is a clear bug in the .NET code under
src/System/Net/Managed/HttpEndPointManager.csinAddPrefixInternal. This method is used for all HttpListener prefixes on non-Windows hosts and uses very basic string parsing which isn't capable of handling IPv6 addresses in any form due to simply treating the first:character as the beginning of the port, which obviously doesn't work for IPv6 addresses which contain:characters.See:
runtime/src/libraries/System.Net.HttpListener/src/System/Net/Managed/HttpEndPointManager.cs
Line 80 in 0ddd0c4