{"record":{"id":"f51d3f6e95fb4052","repo":"NickeManarin/ScreenToGif","slug":"it-was-not-possible-to-get-a-list-of-known-screens","errorCode":null,"errorMessage":"It was not possible to get a list of known screens.","messagePattern":"It was not possible to get a list of known screens\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"ScreenToGif/Windows/NewRecorder.xaml.cs","lineNumber":898,"sourceCode":"            }\n\n            #endregion\n        }\n\n        //Change the scale of the sizing controls.\n        WidthIntegerBox.Scale = UserSettings.All.SelectedRegionScale;\n        HeightIntegerBox.Scale = UserSettings.All.SelectedRegionScale;\n\n        #region Adjust the position of the main controls\n\n        if (_viewModel.Region.IsEmpty)\n        {\n            #region Center on screen\n\n            var screen = _viewModel.Monitors.FirstOrDefault(x => x.Bounds.Contains(CursorHelper.GetMousePosition(1, Left, Top))) ?? _viewModel.Monitors.FirstOrDefault(x => x.IsPrimary) ?? _viewModel.Monitors.FirstOrDefault();\n\n            if (screen == null)\n                throw new Exception(\"It was not possible to get a list of known screens.\");\n\n            MovePanelTo(screen, screen.WorkingArea.Left + screen.WorkingArea.Width / 2 - RecorderWindow.ActualWidth / 2, screen.WorkingArea.Top + screen.WorkingArea.Height / 2 - RecorderWindow.ActualHeight / 2);\n\n            #endregion\n        }\n        else\n        {\n            MoveCommandPanel();\n            DisplaySelection((ModeType) UserSettings.All.RecorderModeIndex);\n        }\n\n        #endregion\n    }\n\n    private void ForceUpdate()\n    {\n        InvalidateMeasure();\n        InvalidateArrange();","sourceCodeStart":880,"sourceCodeEnd":916,"githubUrl":"https://github.com/NickeManarin/ScreenToGif/blob/a4d0a67c2131cd048ceec86cd40afc2f1a06f2fd/ScreenToGif/Windows/NewRecorder.xaml.cs#L880-L916","documentation":"NewRecorder centers the recorder panel when the region is empty by picking a screen from _viewModel.Monitors (the one under the cursor, else the primary, else any). If Monitors is empty the whole chain returns null and it throws — there is literally no enumerated display to center on.","triggerScenarios":"_viewModel.Region.IsEmpty AND _viewModel.Monitors is empty, so the FirstOrDefault(x => Bounds.Contains(...)) ?? FirstOrDefault(IsPrimary) ?? FirstOrDefault() chain yields null.","commonSituations":"Monitor enumeration returned no displays at recorder startup; all displays disconnected after launch; WMI/DXGI enumeration failed silently; headless session; service/context where no user desktop displays exist.","solutions":["Re-enumerate monitors before throwing — call the monitor detection code and rebuild _viewModel.Monitors.","Ensure at least one display is connected and powered on before opening the recorder.","If running over RDP/headless, attach a physical or virtual display.","Fall back to SystemParameters.PrimaryScreen / SystemInformation.VirtualScreen when Monitors is empty."],"exampleFix":"// before\nvar screen = _viewModel.Monitors.FirstOrDefault(x => x.Bounds.Contains(CursorHelper.GetMousePosition(1, Left, Top))) ?? _viewModel.Monitors.FirstOrDefault(x => x.IsPrimary) ?? _viewModel.Monitors.FirstOrDefault();\nif (screen == null)\n    throw new Exception(\"It was not possible to get a list of known screens.\");\n\n// after\nvar screen = _viewModel.Monitors.FirstOrDefault(x => x.Bounds.Contains(CursorHelper.GetMousePosition(1, Left, Top))) ?? _viewModel.Monitors.FirstOrDefault(x => x.IsPrimary) ?? _viewModel.Monitors.FirstOrDefault();\nif (screen == null)\n    throw new Exception(\"It was not possible to get a list of known screens. No display detected — connect a monitor and reopen the recorder.\");","handlingStrategy":"validation","validationCode":"if (_viewModel.Monitors == null || _viewModel.Monitors.Count == 0)\n{\n    await MonitorEnumerator.EnumerateAsync(); // re-populate _viewModel.Monitors\n    if (_viewModel.Monitors.Count == 0) /* warn user: no display detected */\n}","typeGuard":"bool HasAnyMonitor => _viewModel.Monitors?.Any() == true;","tryCatchPattern":"try { /* center panel on screen */ }\ncatch (Exception ex) when (ex.Message.Contains(\"known screens\"))\n{ /* fall back to SystemParameters.PrimaryScreen or warn the user */ }","preventionTips":["Re-enumerate monitors on SystemEvents.DisplaySettingsChanged.","Ensure at least one display is connected before opening the recorder.","Provide a non-throwing fallback rectangle when Monitors is empty."],"tags":["monitor","recorder","display-enumeration","startup"],"backgroundTag":null,"analyzedSha":"a4d0a67c2131cd048ceec86cd40afc2f1a06f2fd","analyzedAt":"2026-08-13T11:12:06.147Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}