wliao008 / buffalo

an aspect oriented programming framework using mono cecil for the .NET platform
1 stars 0 forks source link

PEVerify error: found <uninitialized> ref ( 'this' ptr) #14

Closed wliao008 closed 11 years ago

wliao008 commented 11 years ago

The modified assembly runs ok and display result as expected, but got the following error when verifying with peverify:

[IL]: Error: [C:\Users\Wei.Liao\Documents\Visual Studio 2012\Projects\Test\TestBuffaloMsbuild\TestBuffaloMsbuild\bin\Debug\TestBuffaloMsbuild_modified.exe : TestBuffaloMsbuild.Operation::.ctor][offset 0x00000026][found ref ('this' ptr) 'TestBuffaloMsbuild.Operation'][expected ref 'System.Object'] Unexpected type on the stack.

[IL]: Error: [C:\Users\Wei.Liao\Documents\Visual Studio 2012\Projects\Test\TestBuffaloMsbuild\TestBuffaloMsbuild\bin\Debug\TestBuffaloMsbuild_modified.exe : TestBuffaloMsbuild.Operation::.ctor][offset 0x00000031] Uninitialized this on entering a try block.

2 Error(s) Verifying TestBuffaloMsbuild_modified.exe

using Buffalo;
using System;

namespace TestBuffaloMsbuild
{
    class Program
    {
        static Operation o = new Operation();
        static void Main(string[] args)
        {
            var r = o.Divide(5, 0);
            Console.WriteLine(r);

            Console.Read();
        }
    }

    [Trace]
    public class Operation
    {
        public double Divide(int n1, int n2)
        {
            return n1 / n2;
        }
    }

    public class Trace : MethodBoundaryAspect
    {
        public override void Before(MethodArgs args)
        {
            Console.WriteLine(args.FullName + " is about to execute");
        }

        public override void Exception(MethodArgs args)
        {
            Console.WriteLine("Unhandled exception caught: ");
            if (args.Exception != null)
            {
                Console.WriteLine("args.Exception:");
                Console.WriteLine(args.Exception);

                if (args.Exception.InnerException != null)
                {
                    Console.WriteLine("InnerException:");
                    Console.WriteLine(args.Exception.InnerException);
                }
            }
        }
    }
}
wliao008 commented 11 years ago

This could have something to do with calling ldarg_0 from a static function.