dotnet/wpf · error · ArgumentNullException
ArgumentNullException: destinationFileBaseName
Error message
ArgumentNullException: destinationFileBaseName
What it means
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.
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.
Example fix
// before
fileService.WriteGeneratedCodeFile(content, baseName, ".g.cs", ".g.i.cs", "");
// after
if (string.IsNullOrEmpty(baseName))
throw new ArgumentException("Generated file base name is required", nameof(baseName));
fileService.WriteGeneratedCodeFile(content, baseName, ".g.cs", ".g.i.cs", ""); Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrEmpty(destinationFileBaseName))
throw new ArgumentException("destinationFileBaseName must be non-empty", nameof(destinationFileBaseName)); Type guard
bool HasBaseName(string s) => !string.IsNullOrEmpty(s);
Try / catch
try { fileService.WriteGeneratedCodeFile(content, baseName, ext, iext, langExt); }
catch (ArgumentNullException ex) { log.Error($"Missing generated-file base name: {ex.ParamName}"); throw; } Prevention
- Verify $(IntermediateOutputPath) is set before markup compilation
- Fail fast in the MSBuild task when required properties are empty
- Test design-time (intellisense) builds separately
When it happens
Trigger: Calling WriteGeneratedCodeFile(byte[] contentArray, string destinationFileBaseName, string generatedExtension, string intellisenseGeneratedExtension, string languageSourceExtension) with destinationFileBaseName null or empty.
Common situations: 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.
Related errors
- ArgumentNullException: destinationFile
- annotation component
- ArgumentNullException
- ArgumentNullException(argName)
- ArgumentNullException("characterBufferReference.CharacterBuf…
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/fddf234acb986e7a.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/TaskFileService.cs:331
}
// Save content stream for the given generated code file.
// This function decides which extension to use for the file
// and whether to put it into memory or merely write it to
// disk based on whether it is a real build or an intellisense
// build operation. It also takes care of deleting the corresponding
// unused generated file (i.e. if real build then it deletes
// the intellisense file otherwise it deletes the non-intellisense
// file.
// NOTE: UTF8 BOM should not be added to the contentArray. This
// method adds BOM before writing file to disk.
//
public void WriteGeneratedCodeFile(byte[] contentArray, string destinationFileBaseName,
string generatedExtension, string intellisenseGeneratedExtension, string languageSourceExtension)
{
if (string.IsNullOrEmpty(destinationFileBaseName))
{
throw new ArgumentNullException(nameof(destinationFileBaseName));
}
if (contentArray == null)
{
throw new ArgumentNullException(nameof(contentArray));
}
string buildFile = destinationFileBaseName + generatedExtension + languageSourceExtension;
string intelFile = destinationFileBaseName + intellisenseGeneratedExtension + languageSourceExtension;
string destinationFile = IsRealBuild ? buildFile : intelFile;
UTF8Encoding utf8Encoding = new UTF8Encoding();
string contentStr = utf8Encoding.GetString(contentArray);
// Add BOM for UTF8Encoding since the input contentArray is not supposed to
// have it already.
using (StreamWriter sw = new StreamWriter(destinationFile, false, new UTF8Encoding(true)))View on GitHub (pinned to 81131a70a4)