{"record":{"id":"65928d0b21eb7643","repo":"dotnet/wpf","slug":"sr-documentviewerargumentmustbeinteger","errorCode":null,"errorMessage":"SR.DocumentViewerArgumentMustBeInteger","messagePattern":"SR\\.DocumentViewerArgumentMustBeInteger","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DocumentViewer.cs","lineNumber":1927,"sourceCode":"                // Catch only the expected parse exceptions\n                catch (ArgumentNullException)\n                {\n                    isValidArg = false;\n                }\n                catch (FormatException)\n                {\n                    isValidArg = false;\n                }\n                catch (OverflowException)\n                {\n                    isValidArg = false;\n                }\n            }\n\n            // Argument wasn't a valid int, throw an exception.\n            if (!isValidArg)\n            {\n                throw new ArgumentException(SR.DocumentViewerArgumentMustBeInteger, nameof(data));\n            }\n\n            dv.OnFitToMaxPagesAcrossCommand(columnValue);\n        }\n\n        /// <summary>\n        /// Helper for the Zoom Command, called from ExecutedRoutedEventHandler.\n        /// Verifies that the data passed into ExecutedRoutedEventHandler is valid for a zoom factor\n        /// and sets the Zoom property appropriately.\n        /// </summary>\n        /// <param name=\"dv\">The DocumentViewer that recieved the command</param>\n        /// <param name=\"data\">the data associated with this command</param>\n        private static void DoZoom(DocumentViewer dv, object data)\n        {\n            // Check that args is valid\n            ArgumentNullException.ThrowIfNull(data);\n\n            // If a ZoomConverter doesn't exist, create one.","sourceCodeStart":1909,"sourceCodeEnd":1945,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DocumentViewer.cs#L1909-L1945","documentation":"The static command handler for FitToMaxPagesAcross parses its command parameter (data) as an integer; when parsing fails it throws ArgumentException (SR.DocumentViewerArgumentMustBeInteger) naming the data parameter. This guards command routing where the parameter comes from arbitrary XAML/tool input.","triggerScenarios":"Invoking DocumentViewer.FitToMaxPagesAcrossCommand with a non-integer parameter (e.g. string \"abc\", double, or null that fails parse); XAML Button CommandParameter bound to non-int data.","commonSituations":"CommandParameter bound to a text field; toolbar buttons passing percentages or formatted strings to the pages-across command.","solutions":["Ensure the CommandParameter is an int (or a string parseable via int.TryParse)","Bind CommandParameter to an integer property in the view model","Handle conversion in a value converter before the command executes"],"exampleFix":"// before\nbutton.CommandParameter = \"three\";\n// after\nbutton.CommandParameter = 3;","handlingStrategy":"validation","validationCode":"if (int.TryParse(param as string, out int n)) { /* safe to pass to FitToMaxPagesAcrossCommand */ }","typeGuard":"bool IsIntParam(object p) => p is int || (p is string s && int.TryParse(s, out _));","tryCatchPattern":"try { viewer.FitToMaxPagesAcrossCommand.Execute(param); }\ncatch (ArgumentException) { /* parameter was not an integer */ }","preventionTips":["Bind CommandParameter to int-typed values","Parse/convert strings before issuing commands","Test command bindings with representative UI data"],"tags":["wpf","documentviewer","command","argument-exception"],"backgroundTag":"invalid-argument-format","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"}