Abstract methods cannot be prepared. Parameter name: method

Dec 23, 2016 at 6:32 PM
Hi,
I'm trying to use NConcern framework and I got this error when trying the basic example given on the home page.

Abstract methods cannot be prepared.
Parameter name: method

I'm in a WCF application.

Here are the code used :
    public class Design
    {
        static public Func<MethodInfo,bool> services = new Func<MethodInfo, bool>(method =>
        {
            return method.IsDefined(typeof(OperationContractAttribute), true);
        });

        static public void Init()
        {
            Aspect.Weave<Logging>(services);
        }
    }

static public class Tracer
    {
        static public void Trace(MethodInfo method, object[] arguments)
        {
            Console.WriteLine("{0}{1}", method.Name, string.Join(", ", arguments));
        }
    }

    public class Logging : IAspect
    {
        public IEnumerable<IAdvice> Advise(MethodInfo method)
        {
            yield return Advice.Basic.Before((instance, arguments) =>
            {
                Tracer.Trace(method, arguments);
            });
        }
    }
    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        int Add(int a, int b);

    }
Global.asax
 public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {
            Design.Init();
        }
}
It crashed when It executes the instruction : Aspect.Weave<Logging>(services);

regards,
Dec 23, 2016 at 7:07 PM
Edited Dec 23, 2016 at 7:08 PM
Hi, home page example use WCF "shortcut implementation" by skipping service contract interface definiton. That's why only no abtract methods match with the joinpoint.

Your code will work if you change the joinpoint definition to find method implementation instead of interface methods. It can be a little more complex if reflection is not your concern.

Or you can simply wait a new feature coming with the next release (in few hours : version 2.3) called implicit joinpoint that can do what you need for most of case.