Hi Jabb,

On Sat, Jan 8, 2011 at 4:49 PM, jabb <[email protected]> wrote:
> // Import the DataContractAttribute and get it's default constructor
> var attType =
> module.Import(typeof(System.Runtime.Serialization.DataContractAttribute));
> var attCtor = attType.Resolve().Methods.First(x => x.Name == ".ctor"
> && x.Parameters.Count == 0);

This is actually wrong. Look at what you're doing:

1) You're creating a reference to the type DataContractAttribute
2) You're resolving the reference to a definition, inside another assembly
3) You're using a method defined inside another assembly directly
(which is wrong)

You can either create a reference to the constructor directly:

var attCtor = module.Import (typeof (DataContractAttribute).GetConstructor ());

or create a reference to its definition:

var attCtor = module.Import (attType.Resolve().Methods.First (m =>
m.IsConstructor && !m.HasParameters));

> // At this point, a save results in the following CustomAttribute
> error (from IL Disassembler):
> //    .custom <invalid token 0x06000032> = (01 00 00 00) ...

This should throw with a recent Cecil though. Are you on master?

Jb

-- 
--
mono-cecil

Reply via email to