{"record":{"id":"fddf234acb986e7a","repo":"dotnet/wpf","slug":"argumentnullexception-destinationfilebasename","errorCode":null,"errorMessage":"ArgumentNullException: destinationFileBaseName","messagePattern":"ArgumentNullException: destinationFileBaseName","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/TaskFileService.cs","lineNumber":331,"sourceCode":"        }\n\n        // Save content stream for the given generated code file.\n        // This function decides which extension to use for the file\n        // and whether to put it into memory or merely write it to\n        // disk based on whether it is a real build or an intellisense\n        // build operation. It also takes care of deleting the corresponding\n        // unused generated file (i.e. if real build then it deletes\n        // the intellisense file otherwise it deletes the non-intellisense\n        // file.\n        // NOTE: UTF8 BOM should not be added to the contentArray.  This\n        // method adds BOM before writing file to disk.\n        //\n        public void WriteGeneratedCodeFile(byte[] contentArray, string destinationFileBaseName,\n            string generatedExtension, string intellisenseGeneratedExtension, string languageSourceExtension)\n        {\n            if (string.IsNullOrEmpty(destinationFileBaseName))\n            {\n                throw new ArgumentNullException(nameof(destinationFileBaseName));\n            }\n\n            if (contentArray == null)\n            {\n                throw new ArgumentNullException(nameof(contentArray));\n            }\n\n            string buildFile = destinationFileBaseName + generatedExtension + languageSourceExtension;\n            string intelFile = destinationFileBaseName + intellisenseGeneratedExtension + languageSourceExtension;\n\n            string destinationFile = IsRealBuild ? buildFile : intelFile;\n\n            UTF8Encoding utf8Encoding = new UTF8Encoding();\n            string contentStr = utf8Encoding.GetString(contentArray);\n\n            // Add BOM for UTF8Encoding since the input contentArray is not supposed to\n            // have it already.\n            using (StreamWriter sw = new StreamWriter(destinationFile, false, new UTF8Encoding(true)))","sourceCodeStart":313,"sourceCodeEnd":349,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/TaskFileService.cs#L313-L349","documentation":"TaskFileService.WriteGeneratedCodeFile writes generated code to a build file and an intellisense file derived from destinationFileBaseName. It throws ArgumentNullException when destinationFileBaseName is null or empty because the output file paths cannot be constructed.","triggerScenarios":"Calling WriteGeneratedCodeFile(byte[] contentArray, string destinationFileBaseName, string generatedExtension, string intellisenseGeneratedExtension, string languageSourceExtension) with destinationFileBaseName null or empty.","commonSituations":"MSBuild intermediate output path or generated file base name resolved to empty during XAML markup compilation, often due to a misconfigured project or an intellisense (design-time) build passing an unset path.","solutions":["Ensure the base name (typically IntermediateOutputPath + file name) is non-empty before calling.","Check that $(IntermediateOutputPath) and related properties are set in the build environment.","Add an early validation in the calling task that reports which property was empty."],"exampleFix":"// before\nfileService.WriteGeneratedCodeFile(content, baseName, \".g.cs\", \".g.i.cs\", \"\");\n// after\nif (string.IsNullOrEmpty(baseName))\n    throw new ArgumentException(\"Generated file base name is required\", nameof(baseName));\nfileService.WriteGeneratedCodeFile(content, baseName, \".g.cs\", \".g.i.cs\", \"\");","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(destinationFileBaseName))\n    throw new ArgumentException(\"destinationFileBaseName must be non-empty\", nameof(destinationFileBaseName));","typeGuard":"bool HasBaseName(string s) => !string.IsNullOrEmpty(s);","tryCatchPattern":"try { fileService.WriteGeneratedCodeFile(content, baseName, ext, iext, langExt); }\ncatch (ArgumentNullException ex) { log.Error($\"Missing generated-file base name: {ex.ParamName}\"); throw; }","preventionTips":["Verify $(IntermediateOutputPath) is set before markup compilation","Fail fast in the MSBuild task when required properties are empty","Test design-time (intellisense) builds separately"],"tags":["null-argument","code-generation","wpf-build-tasks"],"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"}