Hi,
I'm adding a field to an assembly with a custom attribute. This custom
attribute takes a Type as a constructor parameter. Inspecting the
generated assembly shows that the actual parameter for the constructor
is set to nullref.
Sample of the code that I used:
[...]
var ca = new CustomAttribute(ctor);
var stringType = asm.MainModule.Import(typeof(string));
ca.ConstructorParameters.Add(stringType);
var field = new FieldDefinition("Test", stringType,
FieldAttributes.Public);
field.CustomAttributes.Add(ca);
[...]
The ctor for the custom attribute looks like this:
public TestAttribute(Type t) { ...}
Inspecting the generated assembly shows the following:
.field public string Test
{
.custom instance void TestAttribute::.ctor(class [mscorlib]
System.Type) = { (nullref) }
}
I did some debugging and noticed the following lines in
SignatureWriter.Write(CustomAttrib,MemoryBinaryWriter)
case ElementType.Type :
string s = elem.Value as string;
if (s == null)
writer.Write ((byte) 0xff);
I tried to replace "elem.Value as string" by elem.Value.ToString(),
and the custom attribute is now properly generated. (I'm not
suggesting a fix, I'm just trying to trace down the problem.)
(... in case of a Type constructor parameter,
ReflectionWriter.CreateElem assign CustomAttrib.Elem.Value to a
TypeReference and not to a string...)
Am I missing something or is this a bug ?
Thanks,
Sebastien
--~--~---------~--~----~------------~-------~--~----~
--
mono-cecil
-~----------~----~----~----~------~----~------~--~---