Hello, my current task is to find & edit or create the finalizer for a certain class. In this case there is no finalizer defined, so the base-finalizer (System.Object) will be used, of course.
I now have to override that Finalizer. I looked up a few solutions which all are obviously outdated (<2011). When I re-compile my assemblies with Cecil, I get the following CIL output: .method family hidebysig virtual instance void <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.Void> *Finalize <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://VisualBug.Lab.Forms:1.0.0.0/VisualBug.Lab.Forms.MainWindow/Finalize()>*() cil managed { .maxstack 8 L_0000: ldarg.0 L_0001: call instance class [mscorlib <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089>]System.Type <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.Type> [mscorlib <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089>]System.Object <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.Object>::GetType <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.Object/GetType():System.Type>() L_0006: ldarg.0 L_0007: ldfld class [App <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://VisualBug.BugSpy:1.1.0.0:dce65d1ef2e32103>]App.Instancing.InstanceId <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://VisualBug.BugSpy:1.1.0.0:dce65d1ef2e32103/VisualBug.BugSpy.Instancing.InstanceId> App.Forms.MainWindow <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://VisualBug.Lab.Forms:1.0.0.0/VisualBug.Lab.Forms.MainWindow>::vbbgsMtrInsVr0221 <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://VisualBug.Lab.Forms:1.0.0.0/VisualBug.Lab.Forms.MainWindow/vbbgsMtrInsVr0221:VisualBug.BugSpy.Instancing.InstanceId> L_000c: call bool <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.Boolean> [App <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://VisualBug.BugSpy:1.1.0.0:dce65d1ef2e32103>]App.Spy <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://VisualBug.BugSpy:1.1.0.0:dce65d1ef2e32103/VisualBug.BugSpy.Spy>::UnsetToken <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://VisualBug.BugSpy:1.1.0.0:dce65d1ef2e32103/VisualBug.BugSpy.Spy/UnsetToken(System.Type,VisualBug.BugSpy.Instancing.InstanceId):Boolean>(class [mscorlib <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089>]System.Type <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.Type>, class [App <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://VisualBug.BugSpy:1.1.0.0:dce65d1ef2e32103>]App.Instancing.InstanceId <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://VisualBug.BugSpy:1.1.0.0:dce65d1ef2e32103/VisualBug.BugSpy.Instancing.InstanceId>) L_0011: pop L_0012: ldarg.0 L_0013: call instance void <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.Void> [mscorlib <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089>]System.Object <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.Object>::Finalize <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.Object/Finalize()>() } .method family hidebysig virtual instance void <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.Void> *Finalize <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://VisualBug.Lab.Forms:1.0.0.0/VisualBug.Lab.Forms.MainWindow/Finalize()>*() cil managed { .maxstack 8 L_0000: ldarg.0 L_0001: call instance class [mscorlib <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089>]System.Type <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.Type> [mscorlib <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089>]System.Object <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.Object>::GetType <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.Object/GetType():System.Type>() L_0006: ldarg.0 L_0007: ldfld class [VisualBug.BugSpy <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://VisualBug.BugSpy:1.1.0.0:dce65d1ef2e32103>]VisualBug.BugSpy.Instancing.InstanceId <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://VisualBug.BugSpy:1.1.0.0:dce65d1ef2e32103/VisualBug.BugSpy.Instancing.InstanceId> VisualBug.Lab.Forms.MainWindow <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://VisualBug.Lab.Forms:1.0.0.0/VisualBug.Lab.Forms.MainWindow>::vbbgsMtrInsVr0221 <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://VisualBug.Lab.Forms:1.0.0.0/VisualBug.Lab.Forms.MainWindow/vbbgsMtrInsVr0221:VisualBug.BugSpy.Instancing.InstanceId> L_000c: call bool <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.Boolean> [VisualBug.BugSpy <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://VisualBug.BugSpy:1.1.0.0:dce65d1ef2e32103>]VisualBug.BugSpy.Spy <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://VisualBug.BugSpy:1.1.0.0:dce65d1ef2e32103/VisualBug.BugSpy.Spy>::UnsetToken <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://VisualBug.BugSpy:1.1.0.0:dce65d1ef2e32103/VisualBug.BugSpy.Spy/UnsetToken(System.Type,VisualBug.BugSpy.Instancing.InstanceId):Boolean>(class [mscorlib <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089>]System.Type <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.Type>, class [VisualBug.BugSpy <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://VisualBug.BugSpy:1.1.0.0:dce65d1ef2e32103>]VisualBug.BugSpy.Instancing.InstanceId <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://VisualBug.BugSpy:1.1.0.0:dce65d1ef2e32103/VisualBug.BugSpy.Instancing.InstanceId>) L_0011: pop L_0012: ldarg.0 L_0013: call instance void <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.Void> [mscorlib <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089>]System.Object <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.Object>::Finalize <http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.Object/Finalize()>() } When I take a look at the same method generated by the compiler, there is a lot more. I guess the Try-Finally stuff is not necessary but probably recommended. But what is clearly missing is the *.override* IL instruction. This is the code that generates the override: destructor = new MethodDefinition("Finalize", MethodAttributes.Family | MethodAttributes.HideBySig | MethodAttributes.Virtual | MethodAttributes.ReuseSlot, module.Import(typeof (void))); baseType.Methods.Add(destructor); How can I achieve this? I don't understand why this won't become a valid override. Every answer on StackOverflow mentioned just those few attributes which have to be set in order to get it working. Obviously that's not enough or has been changed over time (just old answers). Thanks :) -- -- -- mono-cecil --- You received this message because you are subscribed to the Google Groups "mono-cecil" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
