Browse Source

Ignore exceptions in Assembly.DefinedTypes

pull/508/head
Nikita Tsukanov 11 years ago
parent
commit
a7bceef73e
  1. 20
      src/Perspex.DesignerSupport/DesignerAssist.cs

20
src/Perspex.DesignerSupport/DesignerAssist.cs

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
@ -43,9 +44,22 @@ namespace Perspex.DesignerSupport
var plat = (IPclPlatformWrapper) Activator.CreateInstance(Assembly.Load(new AssemblyName("Perspex.Win32"))
.DefinedTypes.First(typeof (IPclPlatformWrapper).GetTypeInfo().IsAssignableFrom).AsType());
var app = plat.GetLoadedAssemblies()
.SelectMany(a => a.DefinedTypes)
.Where(typeof (Application).GetTypeInfo().IsAssignableFrom).FirstOrDefault(t => t.Assembly != typeof (Application).GetTypeInfo().Assembly);
TypeInfo app = null;
foreach (var asm in plat.GetLoadedAssemblies())
{
if(Equals(asm, typeof(Application).GetTypeInfo().Assembly))
continue;
try
{
app = asm.DefinedTypes.Where(typeof (Application).GetTypeInfo().IsAssignableFrom).FirstOrDefault();
if (app != null)
break;
}
catch
{
//Ignore, Assembly.DefinedTypes threw an exception, we can't do anything about that
}
}
if (app == null)
new DesignerApp();
else

Loading…
Cancel
Save