diff --git a/ICSharpCode.Decompiler.Tests/CustomAttributes/S_CustomAttributes.cs b/ICSharpCode.Decompiler.Tests/CustomAttributes/S_CustomAttributes.cs index 47c9ad3bd..ef189c87e 100644 --- a/ICSharpCode.Decompiler.Tests/CustomAttributes/S_CustomAttributes.cs +++ b/ICSharpCode.Decompiler.Tests/CustomAttributes/S_CustomAttributes.cs @@ -42,8 +42,25 @@ namespace aa [My(ULongEnum.MaxUInt64)] public enum ULongEnum : ulong { + [My(null)] MaxUInt64 = 18446744073709551615uL } + [AttributeUsage(AttributeTargets.Class)] + public class TypesAttribute : Attribute + { + public TypesAttribute(Type type) + { + } + } + [Types(typeof(int))] + private class Class1 + { + } + [Types(null)] + private class Class2 + { + } + [My(EnumWithFlag.Item1 | EnumWithFlag.Item2)] private static int field; [My(EnumWithFlag.All)] diff --git a/ICSharpCode.Decompiler/TypeSystem/Implementation/BlobReader.cs b/ICSharpCode.Decompiler/TypeSystem/Implementation/BlobReader.cs index ec1961417..f0839ed71 100644 --- a/ICSharpCode.Decompiler/TypeSystem/Implementation/BlobReader.cs +++ b/ICSharpCode.Decompiler/TypeSystem/Implementation/BlobReader.cs @@ -237,7 +237,12 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation else return new ConversionResolveResult(elementType, elem, Conversion.BoxingConversion); } else if (typeCode == KnownTypeCode.Type) { - return new TypeOfResolveResult(underlyingType, ReadType()); + var type = ReadType(); + if (type != null) { + return new TypeOfResolveResult(underlyingType, type); + } else { + return new ConstantResolveResult(underlyingType, null); + } } else { return new ConstantResolveResult(elementType, ReadElemValue(typeCode)); } @@ -360,7 +365,11 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation case 0x51: // boxed value type return compilation.FindType(KnownTypeCode.Object); case 0x55: // enum - return ReadType(); + var type = ReadType(); + if (type == null) { + throw new NotSupportedException("Enum type should not be null."); + } + return type; default: throw new NotSupportedException(string.Format("Custom attribute type 0x{0:x} is not supported.", b)); } @@ -369,6 +378,9 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation IType ReadType() { string typeName = ReadSerString(); + if (typeName == null) { + return null; + } ITypeReference typeReference = ReflectionHelper.ParseReflectionName(typeName); IType typeInCurrentAssembly = typeReference.Resolve(new SimpleTypeResolveContext(currentResolvedAssembly)); if (typeInCurrentAssembly.Kind != TypeKind.Unknown)