[dotnet-watch] avoid PlatformNotSupportedException on various platforms#52351
Merged
jonathanpeppers merged 1 commit intomainfrom Jan 7, 2026
Merged
[dotnet-watch] avoid PlatformNotSupportedException on various platforms#52351jonathanpeppers merged 1 commit intomainfrom
PlatformNotSupportedException on various platforms#52351jonathanpeppers merged 1 commit intomainfrom
Conversation
…orms
In `Microsoft.Extensions.DotNetDeltaApplier.dll`, which is used by
`dotnet-watch`.
Running `StartupHook.Initialize()` on Android results in:
01-07 14:12:27.328 7304 7304 I DOTNET : System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
01-07 14:12:27.328 7304 7304 I DOTNET : ---> System.PlatformNotSupportedException: Operation is not supported on this platform.
01-07 14:12:27.328 7304 7304 I DOTNET : at System.ConsolePal.set_ForegroundColor(ConsoleColor value)
01-07 14:12:27.328 7304 7304 I DOTNET : at System.Console.set_ForegroundColor(ConsoleColor value)
01-07 14:12:27.328 7304 7304 I DOTNET : at StartupHook.Log(String message)
01-07 14:12:27.328 7304 7304 I DOTNET : at StartupHook.Initialize()
If you review the System.Console APIs, you can see they are decorated with:
[UnsupportedOSPlatform("android")]
[UnsupportedOSPlatform("browser")]
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
* https://github.com/dotnet/runtime/blob/242f7b23752599f22157268de41fee91cb97ef6c/src/libraries/System.Console/src/System/Console.cs#L334-L351
Checking for these platforms makes the exception go away, and we get a
bit further now:
01-07 14:39:37.433 8293 8293 I DOTNET : [HotReload] Environment variable DOTNET_WATCH_HOTRELOAD_NAMEDPIPE_NAME has no value
To be investigated next...
tmat
approved these changes
Jan 7, 2026
baronfel
approved these changes
Jan 7, 2026
51 tasks
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a PlatformNotSupportedException that occurs when using dotnet-watch on Android, iOS, tvOS, and browser platforms. The exception was thrown because Console.ForegroundColor and Console.ResetColor are not supported on these platforms. The fix adds platform checks to conditionally execute console color operations only on supported platforms.
Key Changes
- Added a static readonly field
s_supportsConsoleColorthat checks if the current platform supports console color operations - Wrapped calls to
Console.ForegroundColorandConsole.ResetColorin conditional blocks that checks_supportsConsoleColor
Member
Author
|
/backport to release/10.0.2xx |
Contributor
|
Started backporting to |
jonathanpeppers
added a commit
that referenced
this pull request
Jan 8, 2026
…n` on various platforms (#52355) Backport of #52351 to release/10.0.2xx Co-authored-by: Jonathan Peppers <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In
Microsoft.Extensions.DotNetDeltaApplier.dll, which is used bydotnet-watch.Running
StartupHook.Initialize()on Android results in:If you review the System.Console APIs, you can see they are decorated with:
Checking for these platforms makes the exception go away, and we get a bit further now:
To be investigated next...