-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Open
Labels
area-System.Reflection.Metadatadisabled-testThe test is disabled in source code against the issueThe test is disabled in source code against the issueuntriagedNew issue has not been triaged by the area ownerNew issue has not been triaged by the area owner
Description
Following program throws BadImageFormatException because CustomAttributeDecoder.DecodeFixedArgumentType doesn't handle SignatureTypeCode.GenericTypeInstance.
using System;
using System.Reflection.Metadata;
using System.Reflection.Metadata.Ecma335;
unsafe class Program
{
static void Main()
{
typeof(ClassWithGenericEnumAttribute).Assembly.TryGetRawMetadata(out byte* blob, out int length);
var reader = new MetadataReader(blob, length);
var def = reader.GetTypeDefinition(MetadataTokens.TypeDefinitionHandle(typeof(ClassWithGenericEnumAttribute).MetadataToken));
foreach (var attr in def.GetCustomAttributes())
{
reader.GetCustomAttribute(attr).DecodeValue(new CustomAttributeTypeProvider());
}
}
}
internal class CustomAttributeTypeProvider : ICustomAttributeTypeProvider<object>
{
public object GetPrimitiveType(PrimitiveTypeCode typeCode) => throw new NotImplementedException();
public object GetSystemType() => throw new NotImplementedException();
public object GetSZArrayType(object elementType) => throw new NotImplementedException();
public object GetTypeFromDefinition(MetadataReader reader, TypeDefinitionHandle handle, byte rawTypeKind) => throw new NotImplementedException();
public object GetTypeFromReference(MetadataReader reader, TypeReferenceHandle handle, byte rawTypeKind) => throw new NotImplementedException();
public object GetTypeFromSerializedName(string name) => throw new NotImplementedException();
public PrimitiveTypeCode GetUnderlyingEnumType(object type) => throw new NotImplementedException();
public bool IsSystemType(object type) => throw new NotImplementedException();
}
class GenericEnumAttributeWithFunctionPointer : Attribute
{
public unsafe GenericEnumAttributeWithFunctionPointer(GenericClassForEnum<delegate*<void>[]>.E e) { }
}
class GenericClassForEnum<T>
{
public enum E { }
}
[GenericEnumAttributeWithFunctionPointer(default)]
unsafe class ClassWithGenericEnumAttribute { }Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area-System.Reflection.Metadatadisabled-testThe test is disabled in source code against the issueThe test is disabled in source code against the issueuntriagedNew issue has not been triaged by the area ownerNew issue has not been triaged by the area owner