//on managed code will freeze because it will not be able to continue executing the BrowserDebugProxy to get the locals value
var executablePath = Path.Combine(System.AppContext.BaseDirectory, "BrowserDebugHost.dll");
var ownerPid = Environment.ProcessId;
- var generateRandomPort = new Random().Next(5000, 5300);
+ // generate a random port in a given range, skipping the ports blocked by browsers: https://chromestatus.com/feature/5064283639513088
+ var generateRandomPort = GetNextRandomExcept(5000..5300,
+ 5060, // SIP
+ 5061 // SIPS
+ );
var processStartInfo = new ProcessStartInfo
{
FileName = "dotnet" + (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : ""),
throw new InvalidOperationException("Unable to start debug proxy process.");
}
return generateRandomPort;
+
+ static int GetNextRandomExcept(Range range, params int[] except)
+ {
+ int current;
+ do
+ {
+ current = Random.Shared.Next(range.Start.Value, range.End.Value);
+ } while (Array.IndexOf(except, current) > -1);
+
+ return current;
+ }
}
public void Configure(IApplicationBuilder app,