{"record":{"id":"25f9b37b9ad72808","repo":"dotnet/wpf","slug":"servicetype","errorCode":null,"errorMessage":"serviceType","messagePattern":"serviceType","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextFlow.cs","lineNumber":191,"sourceCode":"\n        /// <summary>\n        /// Gets the service object of the specified type.\n        /// </summary>\n        /// <remarks>\n        /// TextFlow currently supports only TextView and TextContainer.\n        /// </remarks>\n        /// <param name=\"serviceType\">\n        /// An object that specifies the type of service object to get.\n        /// </param>\n        /// <returns>\n        /// A service object of type serviceType. A null reference if there is no \n        /// service object of type serviceType.\n        /// </returns>\n        object IServiceProvider.GetService(Type serviceType)\n        {\n            if (serviceType == null)\n            {\n                throw new ArgumentNullException(\"serviceType\");\n            }\n            if (serviceType == typeof(ITextContainer))\n            {\n                return _structuralCache.TextContainer;\n            }\n            else if (serviceType == typeof(TextContainer))\n            {\n                return _structuralCache.TextContainer as TextContainer;\n            }\n            else if (serviceType == typeof(ITextView))\n            {\n                return this.TextView;\n            }\n            return null;\n        }\n\n        #endregion IServiceProvider Members\n","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextFlow.cs#L173-L209","documentation":"TextFlow's explicit IServiceProvider.GetService implementation throws ArgumentNullException when serviceType is null. The contract requires a concrete service Type; null is not a queryable service identity.","triggerScenarios":"Calling GetService(null) on a TextFlow instance obtained via IServiceProvider (e.g., from a TextEditor/TextContainer service provider context).","commonSituations":"Generic service-locator helper code that forwards an unresolved Type variable; reflection-based code where the requested service type failed to resolve to a Type.","solutions":["Pass a valid Type such as typeof(ITextContainer) or typeof(TextContainer)","Guard the serviceType argument for null before calling GetService","Fix the upstream code that produced a null Type (failed typeof/Type.GetType call)"],"exampleFix":"// before\nvar svc = textFlow.GetService(null);\n\n// after\nif (serviceType != null)\n    var svc = textFlow.GetService(serviceType);","handlingStrategy":"validation","validationCode":"if (serviceType == null) throw new ArgumentNullException(nameof(serviceType));\nvar svc = textFlow.GetService(serviceType);","typeGuard":"bool isValidServiceType(Type t) => t != null;","tryCatchPattern":"try { svc = textFlow.GetService(serviceType); } catch (ArgumentNullException) { /* null type passed; fix caller */ }","preventionTips":["Never build service queries from possibly-null Type variables","Check Type.GetType/typeof results for null before GetService","Request known concrete types like typeof(ITextContainer)"],"tags":["wpf","argumentnull","service-provider"],"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"}