Hi,
I tried something like this:
var firstInstruction = constr.Body.Instructions[0];
var cil = constr.Body.CilWorker;
cil.InsertBefore(firstInstruction, cil.Create(OpCodes.Ldstr, "C:\
\temp\\logfile.log"));
cil.InsertBefore(firstInstruction, cil.Create(OpCodes.Ldstr, "([<\r
\n{0} constructor\r\n{1}\r\n"));
cil.InsertBefore(firstInstruction, cil.Create(OpCodes.Ldstr,
"{0}::.ctor({1})".Fmt(type.FullName,
constr.Parameters.Cast<ParameterDefinition>().Select(pd =>
pd.ParameterType.FullName).JoinString(", "))));
cil.InsertBefore(firstInstruction, cil.Create(OpCodes.Call,
systemEnvironmentGetStackTrace));
cil.InsertBefore(firstInstruction, cil.Create(OpCodes.Call,
systemStringFormat));
cil.InsertBefore(firstInstruction, cil.Create(OpCodes.Call,
systemIOFileAppendAllText));
The variables "systemEnvironmentGetStackTrace" etc. contain a
MethodDefinition that I extracted from mscorlib.dll.
Unfortunately, if I save the assembly with the above modifications, I
get a "Bad method token" error when running it.
How can I fix this so that the inserted IL instructions reference the
correct method in mscorlib?
Thanks
Timwi
--
--
mono-cecil