[Mono-bugs] [Bug 445386] New: MetadataFormatException with custom attributes containing enum array
bugzilla_noreply at novell.com
bugzilla_noreply at novell.com
Fri Nov 14 22:37:31 EST 2008
https://bugzilla.novell.com/show_bug.cgi?id=445386
Summary: MetadataFormatException with custom attributes
containing enum array
Product: Mono: Class Libraries
Version: SVN
Platform: x86-64
OS/Version: openSUSE 11.0
Status: NEW
Severity: Normal
Priority: P5 - None
Component: Cecil
AssignedTo: jbevain at novell.com
ReportedBy: jpryor at novell.com
QAContact: mono-bugs at lists.ximian.com
Found By: ---
I get a Mono.Cecil.Metadata.MetadataFormatException when I have the following:
1. A custom attribute.
2. With an `object' field/property.
3. The field's value is an array of an enumeration type.
Example:
// Mono.Cecil test...
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Mono.Cecil;
namespace Mono.DocTest {
[AttributeUsage (AttributeTargets.All)]
public class DocAttribute : Attribute {
public DocAttribute (string docs)
{
}
public object Any;
}
// [Doc ("c", Any=new int[]{1,2,3})] // nothing
// [Doc ("c", Any=new string[]{"a", "b"})] // nothing
[Doc ("return", Any=new ConsoleModifiers[]{
ConsoleModifiers.Alt,
ConsoleModifiers.Alt | ConsoleModifiers.Control })]
public class Foo {
}
class Test {
public static void Main ()
{
Console.WriteLine (typeof(Foo).Assembly.Location);
AssemblyDefinition a = AssemblyFactory.GetAssembly
(typeof(Foo).Assembly.Location);
TypeDefinition def = a.GetType ("Mono.DocTest.Foo");
foreach (CustomAttribute ca in def.CustomAttributes) {
ca.Resolve ();
var namedArgs =
(from de in ca.Fields.Cast<DictionaryEntry> ()
select new { Type=ca.GetFieldType (de.Key.ToString ()),
Name=de.Key, Value=de.Value })
.Concat (
(from de in ca.Properties.Cast<DictionaryEntry> ()
select new { Type=ca.GetPropertyType (de.Key.ToString ()),
Name=de.Key, Value=de.Value }))
.OrderBy (_ => _.Name);
foreach (var d in namedArgs)
Console.WriteLine ("Name={0}; Type={1}; Module={2}; Value={3}",
d.Name, d.Type, d.Type.Module, d.Value);
}
}
}
static class CecilExtensions {
public static IEnumerable<TypeDefinition> GetTypes (this
AssemblyDefinition assembly)
{
return assembly.Modules.Cast<ModuleDefinition> ()
.SelectMany (md => md.Types.Cast<TypeDefinition> ());
}
public static TypeDefinition GetType (this AssemblyDefinition assembly,
string type)
{
return GetTypes (assembly)
.Where (td => td.FullName == type)
.FirstOrDefault ();
}
}
}
Run: mono --debug foo.exe
Expected output: anything
Actual output:
/home/jon/Development/mono-HEAD/mcs/tools/mdoc/mct.exe
Unhandled Exception: Mono.Cecil.Metadata.MetadataFormatException: Non valid
type in CustomAttrib.Elem: 0x11
at Mono.Cecil.Signatures.SignatureReader.TypeReferenceFromElemType
(ElementType elemType) [0x001ad] in
/home/jon/Development/mono-HEAD/mcs/class/Mono.Cecil/Mono.Cecil.Signatures/SignatureReader.cs:777
at Mono.Cecil.Signatures.SignatureReader.ReadTypeReference (System.Byte[]
data, System.IO.BinaryReader br, Mono.Cecil.Metadata.ElementType& elemType)
[0x00039] in
/home/jon/Development/mono-HEAD/mcs/class/Mono.Cecil/Mono.Cecil.Signatures/SignatureReader.cs:731
at Mono.Cecil.Signatures.SignatureReader.ReadElem (System.Byte[] data,
System.IO.BinaryReader br, Mono.Cecil.TypeReference elemType, System.Boolean&
read, Boolean resolve) [0x0001f] in
/home/jon/Development/mono-HEAD/mcs/class/Mono.Cecil/Mono.Cecil.Signatures/SignatureReader.cs:806
at Mono.Cecil.Signatures.SignatureReader.ReadFixedArg (System.Byte[] data,
System.IO.BinaryReader br, Mono.Cecil.TypeReference param, System.Boolean&
read, Boolean resolve) [0x000b7] in
/home/jon/Development/mono-HEAD/mcs/class/Mono.Cecil/Mono.Cecil.Signatures/SignatureReader.cs:672
at Mono.Cecil.Signatures.SignatureReader.ReadNamedArg (System.Byte[] data,
System.IO.BinaryReader br, System.Boolean& read, Boolean resolve) [0x00083] in
/home/jon/Development/mono-HEAD/mcs/class/Mono.Cecil/Mono.Cecil.Signatures/SignatureReader.cs:794
at Mono.Cecil.Signatures.SignatureReader.ReadCustomAttrib
(System.IO.BinaryReader br, System.Byte[] data, Mono.Cecil.MethodReference
ctor, Boolean resolve) [0x00101] in
/home/jon/Development/mono-HEAD/mcs/class/Mono.Cecil/Mono.Cecil.Signatures/SignatureReader.cs:647
at Mono.Cecil.Signatures.SignatureReader.GetCustomAttrib (System.Byte[] data,
Mono.Cecil.MethodReference ctor, Boolean resolve) [0x0000c] in
/home/jon/Development/mono-HEAD/mcs/class/Mono.Cecil/Mono.Cecil.Signatures/SignatureReader.cs:158
at Mono.Cecil.ReflectionReader.GetCustomAttribute (Mono.Cecil.MethodReference
ctor, System.Byte[] data, Boolean resolve) [0x00000] in
/home/jon/Development/mono-HEAD/mcs/class/Mono.Cecil/Mono.Cecil/ReflectionReader.cs:449
at Mono.Cecil.CustomAttribute.Resolve () [0x00028] in
/home/jon/Development/mono-HEAD/mcs/class/Mono.Cecil/Mono.Cecil/CustomAttribute.cs:186
at Mono.DocTest.Test.Main () [0x00000]
As a potentially related bug, arrays in general don't seem to work as expected.
Try one of the commented-out versions of the [Doc] comment on `class Foo` and
no custom attributes are generated, as if the DocAttribute.Any field hadn't
been specified at all.
--
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
More information about the mono-bugs
mailing list