dotnet/wpf · error · ArgumentNullException
ArgumentNullException: fileName
Error message
ArgumentNullException: fileName
What it means
The InternalsVisibleTo target string is present but malformed: constructing new AssemblyName(assemblyName) throws ArgumentException, and LoadInternalsVisibleToHelper wraps it in XamlSchemaException with SR.BadInternalsVisibleTo2, naming both the bad string and the owning assembly.
Solutions
- Correct the InternalsVisibleTo string to a valid assembly name (e.g. "MyApp.Tests"), matching the friend assembly's simple name.
- Check build/MSBuild properties feeding the attribute for empty values.
- Remove or update stale entries after assembly renames.
- Validate with AssemblyName.TryParse-equivalent logic before shipping the attribute.
Example fix
// before
[assembly: InternalsVisibleTo("")]
// after
[assembly: InternalsVisibleTo("MyApp.Tests")] Defensive patterns
Strategy: validation
Validate before calling
foreach (var a in asm.GetCustomAttributes<InternalsVisibleToAttribute>())
{
try { new AssemblyName(a.AssemblyName); } catch (ArgumentException) { /* fix attribute */ }
} Try / catch
try { new XamlSchemaContext(); } catch (XamlSchemaException ex) when (ex.InnerException is ArgumentException) { /* correct the malformed InternalsVisibleTo string */ } Prevention
- InternalsVisibleTo value must be a valid assembly simple name (optionally with PublicKey)
- Check for empty build-property substitutions in generated attributes
- Update friend names after assembly renames
- Validate with AssemblyName parsing in CI
When it happens
Trigger: new AssemblyName(assemblyName) raising ArgumentException because the InternalsVisibleTo value is not a parseable assembly name (e.g. empty string, illegal characters, missing name), during LoadInternalsVisibleTo.
Common situations: Typos in the friend assembly name; attributes generated from build variables left empty ('' rather than null); renamed assemblies leaving stale InternalsVisibleTo entries; strong-name strings with corrupt public-key blobs.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- Animation_ChildMustBeKeyFrame
- Animation_ChildMustBeKeyFrame
- Animation_NoTextChildren
- Animation_NoTextChildren
- ArgumentException: path
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/968562cba2d5619e.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/TaskFileService.cs:243
else
{
lastChangeDT = File.GetLastWriteTime(srcFile);
}
return lastChangeDT;
}
//
// Checks to see if file exists
//
public bool Exists(string fileName)
{
bool fileExists;
if (fileName == null)
{
throw new ArgumentNullException(nameof(fileName));
}
if (HostFileManager != null)
{
fileExists = HostFileManager.Exists(fileName, IsRealBuild);
}
else
{
fileExists = File.Exists(fileName);
}
return fileExists;
}
//
// Deletes the specified file
//
public void Delete(string fileName)View on GitHub (pinned to 81131a70a4)