{"record":{"id":"968562cba2d5619e","repo":"dotnet/wpf","slug":"argumentnullexception-filename","errorCode":null,"errorMessage":"ArgumentNullException: fileName","messagePattern":"ArgumentNullException: fileName","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/TaskFileService.cs","lineNumber":243,"sourceCode":"            else\n            {\n                lastChangeDT = File.GetLastWriteTime(srcFile);\n            }\n\n            return lastChangeDT;\n        }\n\n\n        //\n        // Checks to see if file exists\n        //\n        public bool Exists(string fileName)\n        {\n            bool fileExists;\n\n            if (fileName == null)\n            {\n                throw new ArgumentNullException(nameof(fileName));\n            }\n\n            if (HostFileManager != null)\n            {\n                fileExists = HostFileManager.Exists(fileName, IsRealBuild);\n            }\n            else\n            {\n                fileExists = File.Exists(fileName);\n            }\n\n            return fileExists;\n        }\n\n        //\n        // Deletes the specified file\n        //\n        public void Delete(string fileName)","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/TaskFileService.cs#L225-L261","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n[assembly: InternalsVisibleTo(\"\")]\n// after\n[assembly: InternalsVisibleTo(\"MyApp.Tests\")]","handlingStrategy":"validation","validationCode":"foreach (var a in asm.GetCustomAttributes<InternalsVisibleToAttribute>())\n{\n    try { new AssemblyName(a.AssemblyName); } catch (ArgumentException) { /* fix attribute */ }\n}","typeGuard":null,"tryCatchPattern":"try { new XamlSchemaContext(); } catch (XamlSchemaException ex) when (ex.InnerException is ArgumentException) { /* correct the malformed InternalsVisibleTo string */ }","preventionTips":["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"],"tags":["xaml","internalsvisibleto","assembly-name","invalid-format","wpf"],"backgroundTag":"invalid-argument-format","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"}