-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dotnet watch
hard exits when it cannot launch browser (due to custom log formatting) in .NET 9
#44251
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
For posterity, here is the output from the sample code above when run: > dotnet watch
dotnet watch 🔥 Hot reload enabled. For a list of supported edits, see https://aka.ms/dotnet/hot-reload.
💡 Press "Ctrl + R" to restart.
Using launch settings from E:\Code\Scratch\json-output\Properties\launchSettings.json...
Building...
{"EventId":14,"LogLevel":"Information","Category":"Microsoft.Hosting.Lifetime","Message":"Now listening on: http://localhost:5205","State":{"Message":"Now listening on: http://localhost:5205","address":"http://localhost:5205","{OriginalFormat}":"Now listening on: {address}"}}
Unhandled exception. System.FormatException: Input string was not in a correct format. Failure to parse near offset 51. Expected an ASCII digit.
at System.Text.ValueStringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ReadOnlySpan`1 args)
at System.String.FormatHelper(IFormatProvider provider, String format, ReadOnlySpan`1 args)
at System.String.Format(String format, Object[] args)
at Microsoft.Extensions.Tools.Internal.MessageDescriptor.TryGetMessage(String prefix, Object[] args, String& message)
at Microsoft.Extensions.Tools.Internal.ConsoleReporter.Report(MessageDescriptor descriptor, String prefix, Object[] args)
at Microsoft.Extensions.Tools.Internal.IReporter.Report(MessageDescriptor descriptor, Object[] args)
at Microsoft.Extensions.Tools.Internal.IReporter.Verbose(String message, String emoji)
at Microsoft.DotNet.Watcher.Tools.BrowserConnector.LaunchBrowser(LaunchSettingsProfile launchProfile, String launchUrl, BrowserRefreshServer server)
at Microsoft.DotNet.Watcher.Tools.BrowserConnector.<>c__DisplayClass11_0.<GetBrowserLaunchTrigger>g__handler|0(Object sender, DataReceivedEventArgs eventArgs)
at System.Diagnostics.AsyncStreamReader.FlushMessageQueue(Boolean rethrowInNewThread)
--- End of stack trace from previous location ---
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart() |
This is happening because a regex is used to scrape the stdout of the running application to get the port the application is bound to. This regex captures too much - in the example stdout I pasted above, the regex captures the following string:
So either the regex needs to be constrained a bit more, or the kind of allowed output for applications needs to be constrained more, or we need a more resilient signalling mechanism here for detecting the ports that webapps are bound to. Is there any kind of run-time introspection here? Maybe @DamianEdwards knows? |
Just to clarify my intention with this issue:
Of course, it'd be ideal if there's a fix that can make |
I think the other tools like VS do this detection by attempting to open a socket to the address specified in the launch profile rather than sniffing console output. Once the socket can be opened it assumes the server is now listening and the browser can be launched. We should of course verify that but perhaps we should move watch to the same mechanism. |
Describe the bug
If using custom log formatting (e.g. JSON) and
"launchBrowser": true
in launchSettings.json,dotnet watch
will hard exit when it fails to launch the browser.To Reproduce
Create a web project using .NET 9 SDK
dotnet new web
Add
builder.Logging.AddJsonConsole();
toProgram.cs
so the full source code isRun
dotnet watch
See an exception printed and the process exits with a non-zero return code. The underlying process that directly runs the project may be orphaned.
Note: If doing the same with .NET 8 SDK, you'd only see a message that says "Unable to launch the browser" but the process doesn't exit.
Exceptions (if any)
Further technical details
The text was updated successfully, but these errors were encountered: