{"record":{"id":"9f75ba6e2c47c737","repo":"dotnet/wpf","slug":"the-exception-argument-cannot-be-null","errorCode":null,"errorMessage":"The exception argument cannot be null.","messagePattern":"The exception argument cannot be null\\.","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsFormsIntegration/System/Windows/Integration/IntegrationExceptionEventArgs.cs","lineNumber":20,"sourceCode":"// The .NET Foundation licenses this file to you under the MIT license.\n\nusing System.Globalization;\n\nnamespace System.Windows.Forms.Integration\n{\n    /// <summary>\n    /// Lets the user preview an exception before the exception is thrown.\n    /// </summary>\n    public class IntegrationExceptionEventArgs : EventArgs\n    {\n        /// <summary>\n        /// Initializes a new instance of the IntegrationExceptionEventArgs class.\n        /// </summary>\n        public IntegrationExceptionEventArgs(bool throwException, Exception exception)\n        {\n            if (exception == null)\n            {\n                throw new ArgumentNullException(string.Format(CultureInfo.CurrentCulture, SR.WFI_NullArgument, \"exception\"));\n            }\n            _throwException = throwException;\n            _exception = exception;\n        }\n\n        private bool _throwException;\n        private Exception _exception;\n\n        /// <summary>\n        /// Determines whether the exception will be thrown.\n        /// </summary>\n        public bool ThrowException\n        {\n            get\n            {\n                return _throwException;\n            }\n            set","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsFormsIntegration/System/Windows/Integration/IntegrationExceptionEventArgs.cs#L2-L38","documentation":"The IntegrationExceptionEventArgs constructor requires a non-null Exception instance. If exception is null it throws ArgumentNullException parameterized with SR.WFI_NullArgument ('The {0} argument cannot be null.'). WPF-WindowsFormsIntegration uses these args to carry exceptions raised during property mapping / integration, so a null exception would make the payload meaningless.","triggerScenarios":"new IntegrationExceptionEventArgs(true, null) — typically when caller code catches without capturing the Exception object, or synthesizes 'failure' args without an actual exception.","commonSituations":"Custom PropertyMap translators or ElementHost/WindowsFormsHost integration callbacks constructing these event args; refactored catch blocks that lost the caught exception variable; logging paths passing null instead of a real exception.","solutions":["Always pass the caught Exception (or a newly constructed Exception/InvalidOperationException describing the failure) to the constructor.","If there is no real exception, use a different event-args type or construct Exception(\"description\") rather than null.","Guard the call site: if (ex != null) new IntegrationExceptionEventArgs(throwException, ex);","Catch ArgumentNullException at the boundary during diagnosis to identify which integration callback passes null."],"exampleFix":"// before\ncatch\n{\n    var args = new IntegrationExceptionEventArgs(true, null);\n}\n// after\ncatch (Exception ex)\n{\n    var args = new IntegrationExceptionEventArgs(true, ex);\n}","handlingStrategy":"type-guard","validationCode":"if (exception == null)\n    throw new InvalidOperationException(\"IntegrationExceptionEventArgs requires a real Exception instance.\");\n\nvar args = new IntegrationExceptionEventArgs(throwException, exception);","typeGuard":"static bool HasException(IntegrationExceptionEventArgs args) => args?.Exception != null;","tryCatchPattern":"try\n{\n    var args = new IntegrationExceptionEventArgs(throwException, ex);\n}\ncatch (ArgumentNullException)\n{\n    var args = new IntegrationExceptionEventArgs(throwException, new InvalidOperationException(\"Unknown integration failure\"));\n}","preventionTips":["Always capture the exception variable in catch blocks (catch (Exception ex)).","Never pass null where an Exception is expected — synthesize a descriptive exception if needed.","Audit integration callbacks that build event args for null-exception paths."],"tags":["wpf","winforms-integration","null-argument","exceptions"],"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"}