From 61204ff38974b878f59b9543f0034b4402929a24 Mon Sep 17 00:00:00 2001 From: Trivalik <3148279+trivalik@users.noreply.github.com> Date: Thu, 28 Apr 2022 08:12:04 +0200 Subject: [PATCH 1/2] fix crash if some assembly not allow GetTypes() i.e. in Microsoft.Practices.Unity, Version=2.1.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 this comes up after migration from xceed AvalonDock version 2. --- .../Components/AvalonDock/Layout/LayoutRoot.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/source/Components/AvalonDock/Layout/LayoutRoot.cs b/source/Components/AvalonDock/Layout/LayoutRoot.cs index ba81f75c..da33b02a 100644 --- a/source/Components/AvalonDock/Layout/LayoutRoot.cs +++ b/source/Components/AvalonDock/Layout/LayoutRoot.cs @@ -653,9 +653,19 @@ void IXmlSerializable.WriteXml(XmlWriter writer) internal static Type FindType(string name) { - foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) - foreach (var type in assembly.GetTypes()) - if (type.Name.Equals(name)) return type; + var avalonAssembly = Assembly.GetAssembly(typeof(LayoutRoot)); + + foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies().OrderBy(a => a != avalonAssembly)) + try + { + foreach (var type in assembly.GetTypes()) + if (type.Name.Equals(name)) + return type; + } + catch (ReflectionTypeLoadException) + { + } + return null; } @@ -995,4 +1005,4 @@ void DumpElement(ILayoutElement element, StringBuilder indent, int childID, bool #endregion Diagnostic tools } -} \ No newline at end of file +} From 4f4177d5cf9fbbba7992a5a159c4b4fa28725fa4 Mon Sep 17 00:00:00 2001 From: Trivalik <3148279+trivalik@users.noreply.github.com> Date: Wed, 11 May 2022 07:51:42 +0200 Subject: [PATCH 2/2] fix build --- source/Components/AvalonDock/Layout/LayoutRoot.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/source/Components/AvalonDock/Layout/LayoutRoot.cs b/source/Components/AvalonDock/Layout/LayoutRoot.cs index da33b02a..ed905d49 100644 --- a/source/Components/AvalonDock/Layout/LayoutRoot.cs +++ b/source/Components/AvalonDock/Layout/LayoutRoot.cs @@ -12,6 +12,7 @@ This program is provided to you under the terms of the Microsoft Public using System.Collections.ObjectModel; using System.Diagnostics; using System.Linq; +using System.Reflection; using System.Text; using System.Windows.Controls; using System.Windows.Markup;