dotnet/wpf · error · XamlSchemaException

SR.BadInternalsVisibleTo2

Error message

SR.BadInternalsVisibleTo2

What it means

LoadInternalsVisibleToHelper throws this XamlSchemaException when the assembly name string from an InternalsVisibleToAttribute cannot be parsed into an AssemblyName (ArgumentException from the constructor). It converts a malformed friend-assembly name into a schema error naming the offending assembly.

Solutions

  1. Use a simple assembly name string (e.g. 'FriendAssembly') in InternalsVisibleTo without invalid qualifiers
  2. Catch XamlSchemaException when scanning third-party assemblies with malformed InternalsVisibleTo attributes
  3. Fix the attribute declaration in the assembly that carries it
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/MS/Impl/XmlNsInfo.cs:292 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/MS/Impl/XmlNsInfo.cs:292

            }

            return result;
        }

        private void LoadInternalsVisibleToHelper(List<AssemblyName> result, string assemblyName, Assembly assembly)
        {
            if (assemblyName is null)
            {
                throw new XamlSchemaException(SR.Format(SR.BadInternalsVisibleTo1, assembly.FullName));
            }

            try
            {
                result.Add(new AssemblyName(assemblyName));
            }
            catch (ArgumentException ex)
            {
                throw new XamlSchemaException(SR.Format(SR.BadInternalsVisibleTo2, assemblyName, assembly.FullName), ex);
            }

            // AssemblyName.ctor throws FLE on malformed assembly name
            catch (FileLoadException ex)
            {
                throw new XamlSchemaException(SR.Format(SR.BadInternalsVisibleTo2, assemblyName, assembly.FullName), ex);
            }
        }

        private Dictionary<string, string> LoadOldToNewNs()
        {
            Dictionary<string, string> result = new Dictionary<string, string>(StringComparer.Ordinal);

            Assembly assembly = Assembly;
            if (assembly is null)
            {
                return result;
            }

View on GitHub (pinned to 81131a70a4)