{"record":{"id":"749f933b00fcf352","repo":"dotnet/wpf","slug":"argumentnullexception-srcfile","errorCode":null,"errorMessage":"ArgumentNullException: srcFile","messagePattern":"ArgumentNullException: srcFile","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/TaskFileService.cs","lineNumber":126,"sourceCode":"            _hostFileManager = null;\n            _isRealBuild = null;\n        }\n\n        #region ITaskFileService\n\n        //\n        // Get content stream for a given source file, the content could\n        // come from memory or disk based on the build host environment.\n        //\n        // It is the caller's responsibility to close the stream.\n        //\n        public Stream GetContent(string srcFile)\n        {\n            Stream fileStream;\n\n            if (string.IsNullOrEmpty(srcFile))\n            {\n                throw new ArgumentNullException(nameof(srcFile));\n            }\n\n            if (HostFileManager != null)\n            {\n                //\n                // Build Host environment has a FileManager, use it to get\n                // file content from edit buffer in memory.  GetFileContents\n                // removes the BOM before returning the string.\n                //\n                string strFileContent = HostFileManager.GetFileContents(srcFile);\n\n\n                // IVsMsBuildTaskFileManager.GetFileContents should never return null.\n                // GetBytes might throw when input is null, but that should be fine.\n                //\n                // For xaml file, UTF8 is the standard encoding\n                //\n                UTF8Encoding utf8Encoding = new UTF8Encoding();","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/TaskFileService.cs#L108-L144","documentation":"While loading XmlnsDefinition assembly attributes, System.Xaml validates each mapping: if the xmlns string is null/empty or the CLR namespace is null, LoadNsDefHelper throws XamlSchemaException with SR.BadXmlnsDefinition naming the offending assembly. The [assembly: XmlnsDefinition] attribute data itself is malformed.","triggerScenarios":"Loading an assembly whose XmlnsDefinition attribute has an empty or null XmlNamespace argument, or a null ClrNamespace; triggered via LoadNsDefs during XamlSchemaContext namespace mapping initialization.","commonSituations":"Hand-edited AssemblyInfo.cs attributes like [assembly: XmlnsDefinition(\"\", \"My.Ns\")]; macro/templated attribute generation producing empty xmlns; third-party control assemblies shipped with bad metadata.","solutions":["Fix the XmlnsDefinition attribute in the offending assembly: supply a non-empty xmlns (e.g. \"http://schemas.example.com/xaml\") and a valid CLR namespace.","Check AssemblyInfo.cs / generate-time templates for empty string arguments.","Identify the assembly from the exception message (assembly.FullName) and inspect its attributes with a decompiler or ilspycmd.","Rebuild/reinstall the control library at a fixed version."],"exampleFix":"// before\n[assembly: XmlnsDefinition(\"\", \"MyApp.Controls\")]\n// after\n[assembly: XmlnsDefinition(\"http://schemas.myapp.com/controls\", \"MyApp.Controls\")]","handlingStrategy":"validation","validationCode":"var a = typeof(SomeTypeInAsm).Assembly;\nbool ok = a.GetCustomAttributes<XmlnsDefinitionAttribute>()\n           .All(x => !string.IsNullOrEmpty(x.XmlNamespace) && x.ClrNamespace != null);","typeGuard":null,"tryCatchPattern":"try { new XamlSchemaContext(); } catch (XamlSchemaException ex) { /* inspect ex.Message for the assembly name, fix its XmlnsDefinition attributes */ }","preventionTips":["Always pass a non-empty xmlns string in XmlnsDefinition attributes","Audit AssemblyInfo.cs of custom control libraries","Run attribute-validation in unit tests for shipped assemblies","Review template/generator scripts that emit these attributes"],"tags":["xaml","xmlns","attribute","assembly-metadata","wpf"],"backgroundTag":"schema-validation-failed","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"}