Skip to content

MacOS 10.13.6 Console.SetWindowSize() exception #27216

Closed

Description

@Petermarcu

I'm opening this on behalf of a user from VS Feedback. https://developercommunity.visualstudio.com/content/problem/318400/macos-10136-consolesetwindowsize-exception.html

dotnet core 2.1 document say support macos

Unhandled Exception: System.PlatformNotSupportedException: Operation is not supported on this platform.
   at System.ConsolePal.SetWindowSize(Int32 width, Int32 height)
   at System.Console.SetWindowSize(Int32 width, Int32 height)
   at ColorConsoleDemo.Program.Main(String[] args) in /Users/zhm/OneDrive/CodeStudy/dotnetcore/ColorConsoleDemo/Program.cs:line 26

code:

using System;
using System.Collections.Generic;

namespace ColorConsoleDemo {
    class Program {
        static void Main (string[] args) {
            List<ConsoleColor> colors = new List<ConsoleColor> ();
            // 遍历枚举的写法,高级用法,把各种颜色保存到List里
            foreach (ConsoleColor color in Enum.GetValues (typeof (ConsoleColor))) {
                colors.Add (color);
            }


            int i = 0;


            // 清楚屏幕,屏幕会被刷为空的背景色
            Console.Clear ();
            // 指定前景色
            Console.ForegroundColor = colors[i % colors.Count];
            // 指定背景色
            Console.BackgroundColor = colors[(i + 1) % colors.Count];
            Console.Write ("Hello");
            Console.ForegroundColor = colors[(i + 2) % colors.Count];
            int origWidth = Console.WindowWidth;
            int origHeight = Console.WindowHeight;
            Console.SetWindowSize (origWidth / 2, origHeight / 2);
            Console.Write (" world!", Console.WindowWidth, Console.WindowHeight);
            Console.SetCursorPosition (80, 15);
            Console.Write ("test");
            Console.SetCursorPosition (81, 16);
            Console.Write ("test");
            Console.SetCursorPosition (82, 17);
            Console.Write ("test");
            Console.SetCursorPosition (83, 18);
            Console.Write ("test");
            Console.SetCursorPosition (84, 19);
            Console.Write ("test");
            System.Threading.Thread.Sleep (1000);
            i++;
        }
    }
}

Activity

  1. stephentoub commented on Sep 25, 2018

    @stephentoub
    Member

    .NET Core 2.1 is supported on macOS, but there are a limited number of APIs that don't work because of platform limitations, and Console.SetWindowSize is one of them, hence the exception.

    @terrajobst or @mairaw can probably comment on the best way tooling or docs could be updated to reflect this, but at present there's no bug here in the implementation; it's by design that it throws PlatformNotSupportedException.

  2. wfurt commented on Oct 15, 2018

    @wfurt
    Member

    note that I get same result on Linux. there is ioctl(TIOCSWINSZ) but that is generally informational.
    It is up to the application to handle it. Also note, that there may not be window at all - at least not local managed by OS. (ssh or serial port access)

  3. transferred this issue fromdotnet/corefxon Jan 31, 2020
  4. added this to the Future milestone on Jan 31, 2020
  5. devklick commented on Feb 4, 2020

    @devklick

    I understand that this will be a pretty low priority, as there really arent that many use cases for setting the console size, but I'd love to see this functionality implemented on Linux, if possible.

  6. wfurt commented on Feb 4, 2020

    @wfurt
    Member

    It is not a matter of priority but more so technical feasibility. Unix "Console" is text-based and does not have window. When starting .NET console app, the app does not own or control the window - it is owned by the terminal app. There is more technical discussion here: #31658

    cc: @tmds

  7. added
    untriaged
    on Feb 23, 2020
  8. removed
    untriaged
    on Apr 1, 2020
  9. junzhou98 commented on Jul 29, 2021

    @junzhou98

    this problem has resolve?

  10. junzhou98 commented on Jul 29, 2021

    @junzhou98

    it can't resolve?

  11. junzhou98 commented on Jul 29, 2021

    @junzhou98

    help

  12. junzhou98 commented on Jul 29, 2021

    @junzhou98

    urgent

  13. wfurt commented on Jul 29, 2021

    @wfurt
    Member

    Are you on 2.1 @junzhou98? 2.1 support will expire in ~ month. Just catch the exception if you cannot avoid the call.
    Alternatively you can p/invoke the icon but that may or may not work. And if it is not, there is no real way IMHO how .NET can make it.

  14. CAMOBAP commented on Sep 22, 2023

    @CAMOBAP

    I assume there is the same exception for Linux/Docker

    P.S. related breadbyte/ConsoleInteractive#9

  15. adamsitnik commented on Nov 13, 2023

    @adamsitnik
    Member

    The issue got fixed by #75824, which is included in .NET 8.

    Some OSes still don't support it, but there is nothing we can do about it:
    https://github.com/dotnet/runtime/blob/0e6e35f3e378e299736fbe07d83ebc339658bbf7/src/libraries/System.Console/src/System/
    Console.cs#L440C1-L450

  16. modified the milestones: Future, 8.0.0 on Nov 13, 2023
  17. locked and limited conversation to collaborators on Dec 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.Consoledocumentationos-linuxos-macos

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions