dotnet/wpf · error · ArgumentNullException

ArgumentNullException: srcFile

Error message

ArgumentNullException: srcFile

What it means

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.

Solutions

  1. 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.
  2. Check AssemblyInfo.cs / generate-time templates for empty string arguments.
  3. Identify the assembly from the exception message (assembly.FullName) and inspect its attributes with a decompiler or ilspycmd.
  4. Rebuild/reinstall the control library at a fixed version.

Example fix

// before
[assembly: XmlnsDefinition("", "MyApp.Controls")]
// after
[assembly: XmlnsDefinition("http://schemas.myapp.com/controls", "MyApp.Controls")]
Defensive patterns

Strategy: validation

Validate before calling

var a = typeof(SomeTypeInAsm).Assembly;
bool ok = a.GetCustomAttributes<XmlnsDefinitionAttribute>()
           .All(x => !string.IsNullOrEmpty(x.XmlNamespace) && x.ClrNamespace != null);

Try / catch

try { new XamlSchemaContext(); } catch (XamlSchemaException ex) { /* inspect ex.Message for the assembly name, fix its XmlnsDefinition attributes */ }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/749f933b00fcf352. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/TaskFileService.cs:126

            _hostFileManager = null;
            _isRealBuild = null;
        }

        #region ITaskFileService

        //
        // Get content stream for a given source file, the content could
        // come from memory or disk based on the build host environment.
        //
        // It is the caller's responsibility to close the stream.
        //
        public Stream GetContent(string srcFile)
        {
            Stream fileStream;

            if (string.IsNullOrEmpty(srcFile))
            {
                throw new ArgumentNullException(nameof(srcFile));
            }

            if (HostFileManager != null)
            {
                //
                // Build Host environment has a FileManager, use it to get
                // file content from edit buffer in memory.  GetFileContents
                // removes the BOM before returning the string.
                //
                string strFileContent = HostFileManager.GetFileContents(srcFile);


                // IVsMsBuildTaskFileManager.GetFileContents should never return null.
                // GetBytes might throw when input is null, but that should be fine.
                //
                // For xaml file, UTF8 is the standard encoding
                //
                UTF8Encoding utf8Encoding = new UTF8Encoding();

View on GitHub (pinned to 81131a70a4)