Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix crash if some assembly not allow GetTypes() #346

Merged
merged 2 commits into from
Jul 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
}