unoplatform/uno · error · FormatException

Invalid typeName: '{0}'

Error message

Invalid typeName: '{0}'

What it means

Thrown by XamlTypeName.Parse when TryParse returns false for the given typeName. Parse is the throwing wrapper over TryParse; the FormatException signals that the type-name string is malformed (bad prefix, unknown namespace, mismatched array/paren brackets, invalid XAML name characters).

Source

Thrown at src/SourceGenerators/System.Xaml/System.Xaml.Schema/XamlTypeName.cs:38

// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;

namespace Uno.Xaml.Schema
{
	[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Types manipulated here have been marked earlier")]
	public class XamlTypeName
	{
		public static XamlTypeName Parse (string typeName, IXamlNamespaceResolver namespaceResolver)
		{
			XamlTypeName n;
			if (!TryParse (typeName, namespaceResolver, out n))
				throw new FormatException (String.Format (CultureInfo.InvariantCulture, "Invalid typeName: '{0}'", typeName));
			return n;
		}

		public static bool TryParse (string typeName, IXamlNamespaceResolver namespaceResolver, out XamlTypeName result)
		{
			if (typeName == null)
				throw new ArgumentNullException ("typeName");
			if (namespaceResolver == null)
				throw new ArgumentNullException ("namespaceResolver");

			result = null;
			IList<XamlTypeName> args = null;
			int nArray = 0;
			int idx;

			if (typeName.Length > 2 && typeName [typeName.Length - 1] == ']') {
				idx = typeName.LastIndexOf ('[');
				if (idx < 0)

View on GitHub (pinned to 0418340488)

Solutions

  1. Use TryParse instead of Parse and handle the false return with a meaningful error.
  2. Ensure the IXamlNamespaceResolver maps every prefix referenced in the type name.
  3. Validate the type name format: `prefix:LocalName` with optional `(args)` and trailing `[]` array suffix.
  4. Use XamlLanguage built-in prefixes for XAML language types instead of inventing prefixes.

Example fix

// before
var name = XamlTypeName.Parse(input, resolver);

// after
if (!XamlTypeName.TryParse(input, resolver, out var name)) {
    throw new FormatException($"Cannot parse XAML type name '{input}'; check prefix and namespace mappings.");
}
Defensive patterns

Strategy: try-catch

Try / catch

try {
    var name = XamlTypeName.Parse(input, resolver);
} catch (FormatException ex) {
    // report the offending type-name string and resolver state
}

Prevention

When it happens

Trigger: Calling XamlTypeName.Parse("x:Int32", resolver) where resolver cannot map prefix 'x'; a type name with mismatched brackets like 'ns:Foo]'; invalid characters in the local name; missing closing paren in a generic arg list.

Common situations: Building type-name strings by hand for XAML type resolution; using a namespace resolver that lacks the required prefix mapping; porting type-name formats between XAML dialects; typos in xmlns prefixes.

Related errors


AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13). Data as JSON: /api/errors/39718e214c8344b6. Report an issue: GitHub.