Browse Source

Handle EnumUnderlyingTypeResolveException in CustomAttribute.DecodeValue()

pull/1030/head
Siegfried Pammer 7 years ago
parent
commit
b6e88c4bbb
  1. 29
      ICSharpCode.Decompiler/TypeSystem/Implementation/CustomAttribute.cs

29
ICSharpCode.Decompiler/TypeSystem/Implementation/CustomAttribute.cs

@ -22,10 +22,7 @@ using System.Collections.Immutable; @@ -22,10 +22,7 @@ using System.Collections.Immutable;
using System.Diagnostics;
using System.Linq;
using System.Reflection.Metadata;
using ICSharpCode.Decompiler.CSharp.Syntax;
using ICSharpCode.Decompiler.Semantics;
using ICSharpCode.Decompiler.Util;
using SRM = System.Reflection.Metadata;
using ICSharpCode.Decompiler.Metadata;
namespace ICSharpCode.Decompiler.TypeSystem.Implementation
{
@ -35,14 +32,14 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation @@ -35,14 +32,14 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
sealed class CustomAttribute : IAttribute
{
readonly MetadataModule module;
readonly SRM.CustomAttributeHandle handle;
readonly CustomAttributeHandle handle;
public IMethod Constructor { get; }
// lazy-loaded:
SRM.CustomAttributeValue<IType> value;
CustomAttributeValue<IType> value;
bool valueDecoded;
internal CustomAttribute(MetadataModule module, IMethod attrCtor, SRM.CustomAttributeHandle handle)
internal CustomAttribute(MetadataModule module, IMethod attrCtor, CustomAttributeHandle handle)
{
Debug.Assert(module != null);
Debug.Assert(attrCtor != null);
@ -71,11 +68,19 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation @@ -71,11 +68,19 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
void DecodeValue()
{
lock (this) {
if (!valueDecoded) {
var metadata = module.metadata;
var attr = metadata.GetCustomAttribute(handle);
value = attr.DecodeValue(module.TypeProvider);
valueDecoded = true;
try {
if (!valueDecoded) {
var metadata = module.metadata;
var attr = metadata.GetCustomAttribute(handle);
value = attr.DecodeValue(module.TypeProvider);
valueDecoded = true;
}
} catch (EnumUnderlyingTypeResolveException) {
value = new CustomAttributeValue<IType>(
ImmutableArray<CustomAttributeTypedArgument<IType>>.Empty,
ImmutableArray<CustomAttributeNamedArgument<IType>>.Empty
);
valueDecoded = true; // in case of errors, never try again.
}
}
}

Loading…
Cancel
Save