Skip to content

Commit

Permalink
Ignore loader errors
Browse files Browse the repository at this point in the history
  • Loading branch information
304NotModified committed May 25, 2017
1 parent ac54511 commit e6e191f
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 12 deletions.
67 changes: 59 additions & 8 deletions tools/DumpApiXml/DocFileBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ private string Capitalize(string p)
return p.Substring(0, 1).ToUpper() + p.Substring(1);
}

private void DumpApiDocs(XmlWriter writer, string kind, string attributeTypeName, string titlePrefix, string titleSuffix)
private void DumpApiDocs(XmlWriter writer, string kind, string attributeTypeName, string titlePrefix, string titleSuffix)
{
foreach (Type type in this.GetTypesWithAttribute(attributeTypeName).OrderBy(t => t.Name))
{
Expand Down Expand Up @@ -608,7 +608,7 @@ private IEnumerable<Type> GetTypesWithAttribute(string attributeTypeName)
{
foreach (Assembly assembly in this.assemblies)
{
foreach (Type t in assembly.GetTypes())
foreach (Type t in assembly.SafeGetTypes())
{
if (HasAttribute(t, attributeTypeName))
{
Expand All @@ -618,28 +618,44 @@ private IEnumerable<Type> GetTypesWithAttribute(string attributeTypeName)
}
}



private bool HasAttribute(Type type, string attributeTypeName)
{
foreach (CustomAttributeData cad in CustomAttributeData.GetCustomAttributes(type))
try
{
if (cad.Constructor.DeclaringType.FullName == attributeTypeName)
foreach (CustomAttributeData cad in CustomAttributeData.GetCustomAttributes(type))
{
return true;
if (cad.Constructor.DeclaringType.FullName == attributeTypeName)
{
return true;
}
}
}
catch
{

}

return false;
}

private bool HasAttribute(PropertyInfo propertyInfo, string attributeTypeName)
{
foreach (CustomAttributeData cad in CustomAttributeData.GetCustomAttributes(propertyInfo))
try
{
if (cad.Constructor.DeclaringType.FullName == attributeTypeName)
foreach (CustomAttributeData cad in CustomAttributeData.GetCustomAttributes(propertyInfo))
{
return true;
if (cad.Constructor.DeclaringType.FullName == attributeTypeName)
{
return true;
}
}
}
catch
{

}

return false;
}
Expand Down Expand Up @@ -729,4 +745,39 @@ private bool TryGetMemberDoc(string id, out XmlElement element)
return false;
}
}

public static class AssemblyExt
{
/// <summary>
/// Gets all usable exported types from the given assembly.
/// </summary>
/// <param name="assembly">Assembly to scan.</param>
/// <returns>Usable types from the given assembly.</returns>
/// <remarks>Types which cannot be loaded are skipped.</remarks>
public static Type[] SafeGetTypes(this Assembly assembly)
{
try
{
return assembly.GetTypes();
}
catch (ReflectionTypeLoadException typeLoadException)
{
foreach (var ex in typeLoadException.LoaderExceptions)
{
//InternalLogger.Warn(ex, "Type load exception.");
}

var loadedTypes = new List<Type>();
foreach (var t in typeLoadException.Types)
{
if (t != null)
{
loadedTypes.Add(t);
}
}

return loadedTypes.ToArray();
}
}
}
}
12 changes: 9 additions & 3 deletions tools/DumpApiXml/DumpApiXml.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand All @@ -10,7 +10,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>DumpApiXml</RootNamespace>
<AssemblyName>DumpApiXml</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<OutputPath>..\..\build\bin\Tools\</OutputPath>
<IntermediateOutputPath>..\..\build\obj\Tools\</IntermediateOutputPath>
<FileAlignment>512</FileAlignment>
Expand All @@ -24,6 +24,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -32,19 +33,24 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Net" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="DocFileBuilder.cs" />
<Compile Include="Program.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="app.config">
<SubType>Designer</SubType>
</None>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
22 changes: 21 additions & 1 deletion tools/DumpApiXml/app.config
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup></configuration>

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.ServiceModel" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="4.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Net" publicKeyToken="7cec85d7bea7798e"/>
<bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="4.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>

<startup>

<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/></startup>

</configuration>

0 comments on commit e6e191f

Please sign in to comment.