{"record":{"id":"a78936c2881005db","repo":"dotnet/wpf","slug":"control","errorCode":null,"errorMessage":"control","messagePattern":"control","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/CalendarVisualStates.cs","lineNumber":148,"sourceCode":"        /// <summary>\n        /// Use VisualStateManager to change the visual state of the control.\n        /// </summary>\n        /// <param name=\"control\">\n        /// Control whose visual state is being changed.\n        /// </param>\n        /// <param name=\"useTransitions\">\n        /// true to use transitions when updating the visual state, false to\n        /// snap directly to the new visual state.\n        /// </param>\n        /// <param name=\"stateNames\">\n        /// Ordered list of state names and fallback states to transition into.\n        /// Only the first state to be found will be used.\n        /// </param>\n        public static void GoToState(Control control, bool useTransitions, params string[] stateNames)\n        {\n            if (control == null)\n            {\n                throw new ArgumentNullException(\"control\");\n            }\n\n            if (stateNames == null)\n            {\n                return;\n            }\n\n            foreach (string name in stateNames)\n            {\n                if (VisualStateManager.GoToState(control, name, useTransitions))\n                {\n                    break;\n                }\n            }\n        }\n    }\n}","sourceCodeStart":130,"sourceCodeEnd":165,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/CalendarVisualStates.cs#L130-L165","documentation":"CalendarVisualStates.GoToState is a helper that forwards a control to VisualStateManager.GoToState for the first matching state name. It validates that the Control argument is non-null and throws ArgumentNullException named \"control\" otherwise.","triggerScenarios":"Calling CalendarVisualStates.GoToState(null, true, \"StateName\") — passing a null control, often from a templated-control code path where the templated parent or a part lookup returned null.","commonSituations":"Custom control OnApplyTemplate where GetTemplateChild returned null and the result is passed to GoToState; generic code invoking the helper before the control instance is created.","solutions":["Pass a valid, non-null Control instance.","Check template part lookups: if control is null because a part wasn't found, fix the template/part name instead.","If you own the call site, guard with a null check or use ArgumentNullException.ThrowIfNull semantics before calling."],"exampleFix":"// before\nCalendarVisualStates.GoToState(part, true, \"Normal\");\n// after\nif (part != null)\n    CalendarVisualStates.GoToState(part, true, \"Normal\");","handlingStrategy":"type-guard","validationCode":"if (control == null) return; // or log missing template part","typeGuard":"static bool CanGoToState(Control c) => c != null;","tryCatchPattern":"try { CalendarVisualStates.GoToState(control, useTransitions, states); }\ncatch (ArgumentNullException ex) { log.Error(\"GoToState called with null control\", ex); }","preventionTips":["Check GetTemplateChild results for null in OnApplyTemplate","Never call GoToState before the control instance exists","Coalesce null controls into early returns in shared helpers"],"tags":["wpf","null-argument","visual-states","controls"],"backgroundTag":"null-argument","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}