提交 fe7e3160 编写于 作者: C CyrusNajmabadi

Be resilient to when we get an exception while reading metadata.

上级 b280c27c
......@@ -162,6 +162,9 @@ internal Metadata GetMetadataNoCopy()
/// Returns a copy of the <see cref="Metadata"/> object this <see cref="PortableExecutableReference"/>
/// contains. This copy does not need to be <see cref="IDisposable.Dispose"/>d.
/// </summary>
/// <exception cref="BadImageFormatException">If the PE image format is invalid.</exception>
/// <exception cref="IOException">The metadata image content can't be read.</exception>
/// <exception cref="FileNotFoundException">The metadata image is stored in a file that can't be found.</exception>
public Metadata GetMetadata()
{
return GetMetadataNoCopy().Copy();
......
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Metadata;
......@@ -13,6 +14,18 @@ namespace Microsoft.CodeAnalysis.FindSymbols
{
internal partial class SymbolTreeInfo
{
private static Metadata GetMetadataNoThrow(PortableExecutableReference reference)
{
try
{
return reference.GetMetadata();
}
catch (Exception e) when (e is BadImageFormatException || e is IOException)
{
return null;
}
}
/// <summary>
/// this gives you SymbolTreeInfo for a metadata
/// </summary>
......@@ -22,7 +35,7 @@ internal partial class SymbolTreeInfo
bool loadOnly,
CancellationToken cancellationToken)
{
var metadata = reference.GetMetadata();
var metadata = GetMetadataNoThrow(reference);
if (metadata == null)
{
return null;
......@@ -76,7 +89,7 @@ internal partial class SymbolTreeInfo
{
var unsortedNodes = new List<Node> { new Node("", Node.RootNodeParentIndex) };
foreach (var moduleMetadata in GetModuleMetadata(reference.GetMetadata()))
foreach (var moduleMetadata in GetModuleMetadata(GetMetadataNoThrow(reference)))
{
MetadataReader reader;
try
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册