Maybe I could use ldftn instead...? On Nov 29, 1:52 pm, Jeff Nevins <[email protected]> wrote: > This is the IL code crashes Reflector when switching to C# (or VB.NET) > mode. I've marked the culprit lines. If I ldnull instead of ldtoken, > Reflector doesn't bug out anymore. It happens on all woven methods, > not just this one. It's kind of important that this work, since > developers may need to debug the woven code... Suggestions are much > appreciated. > > Thanks. > > .method public hidebysig specialname rtspecialname instance > void .ctor() cil managed > { > .maxstack 4 > .locals init ( > [0] class > [WorkstationWeaver]WorkstationWeaver.PreInvocationContext context) > L_0000: ldarg.0 > L_0001: ldnull > L_0002: stfld class [System]System.ComponentModel.IContainer > Workstation.Applications.Common.Diagnostics.SomeClassCP::components > L_0007: ldarg.0 > L_0008: call instance void > Workstation.Applications.Common.UI.Content.ContentPaneBase::.ctor() > L_000d: ldarg.0 > XXXXXX L_000e: ldtoken instance void > Workstation.Applications.Common.Diagnostics.SomeClassCP::.ctor() > XXXXXX L_0013: ldtoken > Workstation.Applications.Common.Diagnostics.SomeClassCP > L_0018: newobj instance void > [WorkstationWeaver]WorkstationWeaver.PreInvocationContext::.ctor(object, > valuetype [mscorlib]System.RuntimeMethodHandle, valuetype > [mscorlib]System.RuntimeTypeHandle) > L_001d: stloc.0 > L_001e: ldloc.0 > L_001f: ldc.i4.0 > L_0020: call void > [WorkstationWeaver]WorkstationWeaver.InterceptionContext::OnPreInvocation(class > [WorkstationWeaver]WorkstationWeaver.PreInvocationContext, bool) > L_0025: nop > L_0026: nop > L_0027: ldarg.0 > L_0028: call instance void > Workstation.Applications.Common.Diagnostics.SomeClassCP::InitializeComponent() > L_002d: nop > L_002e: ldarg.0 > L_002f: call instance void > Workstation.Applications.Common.Diagnostics.SomeClassCP::Init() > L_0034: nop > L_0035: nop > L_0036: ldarg.0 > XXXXXX L_0037: ldtoken instance void > Workstation.Applications.Common.Diagnostics.SomeClassCP::.ctor() > XXXXXX L_003c: ldtoken > Workstation.Applications.Common.Diagnostics.SomeClassCP > L_0041: ldloc.0 > L_0042: callvirt instance object > [WorkstationWeaver]WorkstationWeaver.PreInvocationContext::get_CorrelationState() > L_0047: newobj instance void > [WorkstationWeaver]WorkstationWeaver.PostInvocationContext::.ctor(object, > valuetype [mscorlib]System.RuntimeMethodHandle, valuetype > [mscorlib]System.RuntimeTypeHandle, object) > L_004c: call void > [WorkstationWeaver]WorkstationWeaver.InterceptionContext::OnPostInvocation(class > [WorkstationWeaver]WorkstationWeaver.PostInvocationContext) > L_0051: ret > > } > > On Nov 29, 1:23 pm, Jb Evain <[email protected]> wrote: > > > On Mon, Nov 29, 2010 at 7:13 PM, Jeff Nevins <[email protected]> wrote: > > > Works great! Peverifies fine, but for some reason when I use the code: > > > > processor.InsertBefore(insertBefore, processor.Create(OpCodes.Ldtoken, > > > method.Module.Import(method))); > > > > When viewing in C# mode in Reflector it bugs out and crashes (IL mode > > > displays fine). > > > > Anyone have any ideas on this one? > > > It may be simply be the case that the code you're injecting is > > confusing Reflector's decompiler. Especially as `ldtoken method` has > > no C# representation (iirc, Reflector outputs a non existing methodof > > operator in this case), so in the end, it's impossible to know without > > having a full IL sample of a method after you instrumented it. > >
-- -- mono-cecil
