Browse Source

Improved XAML type resolution exception

pull/11347/head
Yoh Deadfall 3 years ago
parent
commit
083fcb54e0
  1. 17
      src/Markup/Avalonia.Markup.Xaml/XamlIl/Runtime/XamlIlRuntimeHelpers.cs

17
src/Markup/Avalonia.Markup.Xaml/XamlIl/Runtime/XamlIlRuntimeHelpers.cs

@ -154,20 +154,19 @@ namespace Avalonia.Markup.Xaml.XamlIl.Runtime
var namespaces = _nsInfo.XmlNamespaces; var namespaces = _nsInfo.XmlNamespaces;
if (!namespaces.TryGetValue(ns, out var lst)) if (!namespaces.TryGetValue(ns, out var lst))
throw new ArgumentException("Unable to resolve namespace for type " + qualifiedTypeName); throw new ArgumentException("Unable to resolve namespace for type " + qualifiedTypeName);
foreach (var entry in lst) var resolvable = lst.Where(static e => e.ClrAsseblyName is { Length: > 0 });
foreach (var entry in resolvable)
{ {
if (entry.ClrAssemblyName is { Length: > 0 }) var asm = Assembly.Load(new AssemblyName(entry.ClrAssemblyName));
{ var resolved = asm.GetType(entry.ClrNamespace + "." + name);
var asm = Assembly.Load(new AssemblyName(entry.ClrAssemblyName)); if (resolved != null)
var resolved = asm.GetType(entry.ClrNamespace + "." + name); return resolved;
if (resolved != null)
return resolved;
}
} }
throw new ArgumentException( throw new ArgumentException(
$"Unable to resolve type {qualifiedTypeName} from any of the following locations: " + $"Unable to resolve type {qualifiedTypeName} from any of the following locations: " +
string.Join(",", lst.Select(e => $"`{e.ClrAssemblyName}:{e.ClrNamespace}.{name}`"))); string.Join(",", resolvable.Select(e => $"`clr-namespace:{e.ClrNamespace};assembly={e.ClrAssemblyName}`")))
{ HelpLink = "https://docs.avaloniaui.net/guides/basics/introduction-to-xaml#valid-xaml-namespaces" };
} }
} }

Loading…
Cancel
Save