Management automation host rectangle: bottom cannot be greater than or equal to top

73 Views Asked by At

I'm getting an error saying bottom cannot be greater than or equal to top.

I'm using the Rectangle constructor documented here: https://learn.microsoft.com/en-us/dotnet/api/system.management.automation.host.rectangle.-ctor?view=powershellsdk-1.1.0#System_Management_Automation_Host_Rectangle__ctor_System_Int32_System_Int32_System_Int32_System_Int32_

This is my relevant section of code;

            Console.WriteLine("setting rectangles: " + sizex +", " +sizey);
            int screenTop = sizey;
            int screenBottom = 1;
            int statusTop = 1;
            int statusBottom = 0;
            Console.WriteLine ("screen top bottom; "+screenTop + " > " + screenBottom );
            Console.WriteLine ("status top bottom; "+statusTop + " > " + statusBottom );
            
         // Rectangle(int left, int top, int right, int bottom);
            System.Management.Automation.Host.Rectangle screenWindowRect = new Rectangle(0,screenTop,sizex,screenBottom);
            System.Management.Automation.Host.Rectangle statusLineRect = new Rectangle(0,statusTop,sizex,statusBottom);
            Console.WriteLine("rectangles set");

I see the debug lines before the constructors, but never the "rectangles set" message.

This is the output;

setting rectangles: 241, 28
screen top bottom; 28 > 1
status top bottom; 1 > 0
Out-Less: "bottom" cannot be greater than or equal to "top".

I can see that top is greater than bottom but I keep getting the error; "bottom" cannot be greater than or equal to "top"

Is this a bug, or documentation error, or is there something I'm missing.

1

There are 1 best solutions below

0
On BEST ANSWER

The error message misstates the actual error condition:

"bottom" cannot be greater than or equal to "top"

should be:

"bottom" cannot be less than "top"

In other words: the bottom argument must be equal to or greater than the top argument - and, analogously, right must be equal to or greater than left:

You can verify this in PowerShell itself:

# OK: 1 -ge 1
# Arguments are: left, top, right, bottom
[System.Management.Automation.Host.Rectangle]::new(0, 1, 0, 1)

# OK: 2 -ge 1
[System.Management.Automation.Host.Rectangle]::new(0, 1, 0, 2)

# !! EXCEPTION: 0 -ge 1 is NOT true.
[System.Management.Automation.Host.Rectangle]::new(0, 1, 0, 0)