Arun Singh
Arun Singh

Reputation: 647

Postsharp Aspect class OnEntry Method is not calling from web api controller

As, I am working on web api project and trying to implement the PostSharp Aspect class to loggin the request and other staff. OnEntry method OnSucess method is not getting called when api method is calling. If I use same Aspect class in other MVC project which already in same solution then that works. Only Aspect class not executing in web api project.

I have already added the Postsharp DLL in web api project.

enter image description here

Aspect class

enter image description here

Web api controller

enter image description here

Upvotes: 0

Views: 142

Answers (1)

Daniel Balas
Daniel Balas

Reputation: 1850

PostSharp is a post-compiler and it needs to integrate with the build process. This is done through the MSBuild target file PostSharp.targets and just having the assembly reference is not enough.

Most likely your project does not import this target file.

It is included in PostSharp NuGet package and should be automatically imported if your project uses PackageReference style of NuGet package references. If you are using packages.config, you need to make sure that your project file includes <Import Project="<path_to_package>\PostSharp.targets" />. This may be sometimes missing after upgrading the package or if you have manually added the reference.

Similarly, if you are using Zip distro, this import needs to be present in your project file and pointing to the directory where PostSharp is unzipped.

Upvotes: 0

Related Questions