From 7295446fe1b8120190ba19a25b41d77f8bdb4be3 Mon Sep 17 00:00:00 2001 From: Yoh Deadfall Date: Fri, 12 May 2023 23:14:39 +0300 Subject: [PATCH 1/3] Ignore xmlns without CLR namespace on type resolution --- .../XamlIl/Runtime/XamlIlRuntimeHelpers.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Markup/Avalonia.Markup.Xaml/XamlIl/Runtime/XamlIlRuntimeHelpers.cs b/src/Markup/Avalonia.Markup.Xaml/XamlIl/Runtime/XamlIlRuntimeHelpers.cs index f8eab5b654..a78af8e35c 100644 --- a/src/Markup/Avalonia.Markup.Xaml/XamlIl/Runtime/XamlIlRuntimeHelpers.cs +++ b/src/Markup/Avalonia.Markup.Xaml/XamlIl/Runtime/XamlIlRuntimeHelpers.cs @@ -156,10 +156,13 @@ namespace Avalonia.Markup.Xaml.XamlIl.Runtime throw new ArgumentException("Unable to resolve namespace for type " + qualifiedTypeName); foreach (var entry in lst) { - var asm = Assembly.Load(new AssemblyName(entry.ClrAssemblyName)); - var resolved = asm.GetType(entry.ClrNamespace + "." + name); - if (resolved != null) - return resolved; + if (entry.ClrAssemblyName is { Length: > 0 }) + { + var asm = Assembly.Load(new AssemblyName(entry.ClrAssemblyName)); + var resolved = asm.GetType(entry.ClrNamespace + "." + name); + if (resolved != null) + return resolved; + } } throw new ArgumentException( From 083fcb54e0f4781dfd5a94a93480bfa84e7ddc0a Mon Sep 17 00:00:00 2001 From: Yoh Deadfall Date: Fri, 12 May 2023 23:49:39 +0300 Subject: [PATCH 2/3] Improved XAML type resolution exception --- .../XamlIl/Runtime/XamlIlRuntimeHelpers.cs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/Markup/Avalonia.Markup.Xaml/XamlIl/Runtime/XamlIlRuntimeHelpers.cs b/src/Markup/Avalonia.Markup.Xaml/XamlIl/Runtime/XamlIlRuntimeHelpers.cs index a78af8e35c..5b8388594f 100644 --- a/src/Markup/Avalonia.Markup.Xaml/XamlIl/Runtime/XamlIlRuntimeHelpers.cs +++ b/src/Markup/Avalonia.Markup.Xaml/XamlIl/Runtime/XamlIlRuntimeHelpers.cs @@ -154,20 +154,19 @@ namespace Avalonia.Markup.Xaml.XamlIl.Runtime var namespaces = _nsInfo.XmlNamespaces; if (!namespaces.TryGetValue(ns, out var lst)) 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); - if (resolved != null) - return resolved; - } + var asm = Assembly.Load(new AssemblyName(entry.ClrAssemblyName)); + var resolved = asm.GetType(entry.ClrNamespace + "." + name); + if (resolved != null) + return resolved; } throw new ArgumentException( $"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" }; } } From 75eb8a78d4e88c709ca21fae54ee6aa34d2ee361 Mon Sep 17 00:00:00 2001 From: Yoh Deadfall Date: Mon, 15 May 2023 13:21:05 +0300 Subject: [PATCH 3/3] Fixed typo --- .../Avalonia.Markup.Xaml/XamlIl/Runtime/XamlIlRuntimeHelpers.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Markup/Avalonia.Markup.Xaml/XamlIl/Runtime/XamlIlRuntimeHelpers.cs b/src/Markup/Avalonia.Markup.Xaml/XamlIl/Runtime/XamlIlRuntimeHelpers.cs index 5b8388594f..be6b37bb02 100644 --- a/src/Markup/Avalonia.Markup.Xaml/XamlIl/Runtime/XamlIlRuntimeHelpers.cs +++ b/src/Markup/Avalonia.Markup.Xaml/XamlIl/Runtime/XamlIlRuntimeHelpers.cs @@ -154,7 +154,7 @@ namespace Avalonia.Markup.Xaml.XamlIl.Runtime var namespaces = _nsInfo.XmlNamespaces; if (!namespaces.TryGetValue(ns, out var lst)) throw new ArgumentException("Unable to resolve namespace for type " + qualifiedTypeName); - var resolvable = lst.Where(static e => e.ClrAsseblyName is { Length: > 0 }); + var resolvable = lst.Where(static e => e.ClrAssemblyName is { Length: > 0 }); foreach (var entry in resolvable) { var asm = Assembly.Load(new AssemblyName(entry.ClrAssemblyName));