Skip to content

Commit

Permalink
Merge pull request #346 from trivalik/patch-1
Browse files Browse the repository at this point in the history
fix crash if some assembly not allow GetTypes()
  • Loading branch information
Dirkster99 authored Jul 16, 2022
2 parents 617a313 + 4f4177d commit 255ee11
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions source/Components/AvalonDock/Layout/LayoutRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -653,9 +654,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;
}

Expand Down Expand Up @@ -995,4 +1006,4 @@ void DumpElement(ILayoutElement element, StringBuilder indent, int childID, bool

#endregion Diagnostic tools
}
}
}

0 comments on commit 255ee11

Please # to comment.