views:

188

answers:

1

HI,

I'm using PostSharp to log entry and exit to every method in my Application assembly. This assembly is strongly named, versioned and registered in the GAC.

It is then shared by 2 web service projects hosted in separate Virtual Directories inside IIS. When the OnEntry/OnExit method of the interceptor is invoked by WebServiceProject1 it works fine, however when they are then invoked by WebServiceProject2, the MethodExecutionEventArgs.Method value passed into the interceptor seems to be null and I get a NullReferenceException.

If you restart IIS and invoke the web service projects in the order WebServiceProject2, WebServiceProject1 then again the first one to invoke works, and the other throws a NullReferenceException in the same way. The code is shown below:

[Serializable]
[Log(AttributeExclude = true)]
[AttributeUsage(AttributeTargets.All)]
public sealed class LogAttribute : OnMethodBoundaryAspect
{
  public override void OnEntry(MethodExecutionEventArgs eventArgs)
  {
    IoC.Resolve<ILogger>().WriteMethodEntry(eventArgs.Method, eventArgs.GetReadOnlyArgumentArray());
  }

  public override void OnExit(MethodExecutionEventArgs eventArgs)
  {
    IoC.Resolve<ILogger>().WriteMethodExit(eventArgs.Method, eventArgs.ReturnValue);
  }
}

Interestingly, if I remove the assembly from the GAC and make the webservice projects run off the \bin subdirectory copy, it works fine. I don't want to do this however as another part of the application relies on the assemblies being in the GAC, and I don't want lots of different versions of the same DLL in different places.

It is similar to the issue described here : http://generatedbyatool.net/content/post/2009/07/27/PostSharp-Bug-or-How-To-Recycle-Your-Own-App-Pool.aspx but there are obvious differences.

Anyone got any ideas or advice? I'm going to try to build a standalone application to prove this today.

Stoo

A: 

Hi Steve!

Could you please report this problem to http://www.postsharp.org/tracker?

Note that there are known problem when the assembly to be processed is in GAC. The assembly must NOT be in GAC (even an old version, if it has the same version number) when PostSharp processes it. You should remove it in a pre-build step.

However, if PostSharp ran properly, I see no reason why the method is not passed. Did you try to see in Reflector what happens?

-gael

Gael Fraiteur
I have raised this on the Postsharp forum with a simple example attached. http://www.postsharp.org/forum/postsharp-laos/null-reference-exception-methodexecutioneventargs-method-t994.html I will add it to the tracker.
Stewart Roberts
I have added the issue to Mantis - ID0000415. Thanks for your help. Let me know if there is anything I can do to help...
Stewart Roberts