EmbedIO.WebServer server = new EmbedIO.WebServer(
configure => configure
.WithUrlPrefix("http://somehost/")
.WithMode(HttpListenerMode.EmbedIO)
)
See error
Unhandled Exception: L2 14:08:28.327273 (14016-26404) [AddListener] Length cannot be less than zero.
Parameter name: length; Length cannot be less than zero.
Parameter name: length at System.String.Substring(Int32 startIndex, Int32 length)
at EmbedIO.Net.Internal.ListenerPrefix..ctor(String uri) in D:\dev\embedio\src\EmbedIO\Net\Internal\ListenerPrefix.cs:line 29
at EmbedIO.Net.EndPointManager.AddPrefix(String p, HttpListener listener) in D:\dev\embedio\src\EmbedIO\Net\EndPointManager.cs:line 75
System.ArgumentOutOfRangeException: Length cannot be less than zero.
Parameter name: length
ndPointManager.AddListener(HttpListener listener) in D:\dev\embedio\src\EmbedIO\Net\EndPointManager.cs:line 48
at System.String.Substring(Int32 startIndex, Int32 length)
at EmbedIO.Net.HttpListener.Start() in D:\dev\embedio\src\EmbedIO\Net\HttpListener.cs:line 65
at EmbedIO.Net.Internal.ListenerPrefix..ctor(String uri) in D:\dev\embedio\src\EmbedIO\Net\Internal\ListenerPrefix.cs:line 29
at EmbedIO.Net.EndPointManager.AddPrefix(String p, HttpListener listener) in D:\dev\embedio\src\EmbedIO\Net\EndPointManager.cs:line 75
ken cancellationToken) in D:\dev\embedio\src\EmbedIO\WebServer.cs:line 140
at EmbedIO.Net.EndPointManager.AddListener(HttpListener listener) in D:\dev\embedio\src\EmbedIO\Net\EndPointManager.cs:line 48
at EmbedIO.WebServerBase`1.<RunAsync>d__39.MoveNext() in D:\dev\embedio\src\EmbedIO\WebServerBase`1.cs:line 198
at EmbedIO.Net.HttpListener.Start() in D:\dev\embedio\src\EmbedIO\Net\HttpListener.cs:line 65
Expected behavior
Parse the listener prefix without an exception and use the default port 80 as the port number.
Additional context
The error seems to be related to the line:
var colon = uri.LastIndexOf(':');
If there is no port-related colon, this will find the index of the colon after the URI scheme ("http:"). The later (port-related) colon index check,
Listener prefix parsing issue. An exception is thrown when parsing a listener prefix that uses an implicit default HTTP port (80).
To Reproduce Steps to reproduce the behavior:
Expected behavior Parse the listener prefix without an exception and use the default port 80 as the port number.
Additional context The error seems to be related to the line:
If there is no port-related colon, this will find the index of the colon after the URI scheme ("http:"). The later (port-related) colon index check,
will incorrectly pass and in the next line the computed Substring index will be negative and trigger the exception.