Using post sharp with web projects?
25 posts • Page 1 of 3 • 1, 2, 3
Using post sharp with web projects?
I can't seem to get PostSharp working on my c# asp.net web service project. Are there additional configuration needed to get Laos to work with web projects?
Thanks
- dawginlife
- Posts: 6
- Joined: Sat Jan 12, 2008 4:55 pm
Re: Using post sharp with web projects?
Hi wanginlife,
Actually I've to admit I've never tried to use PostSharp with web projects. But it should work, and if it does not, it is a bug.
The best is that you send me your zipped test application (if possible). One of the options is to upload it on [url=ftp://ftp.postsharp.org/upload]ftp://ftp.postsharp.org/upload[/url] or to attach it to a forum post.
Gael
Actually I've to admit I've never tried to use PostSharp with web projects. But it should work, and if it does not, it is a bug.
The best is that you send me your zipped test application (if possible). One of the options is to upload it on [url=ftp://ftp.postsharp.org/upload]ftp://ftp.postsharp.org/upload[/url] or to attach it to a forum post.
Gael
Gael Fraiteur, project leader
got good support? consider donating to the project.
got good support? consider donating to the project.
- gfraiteur
- Site Admin
- Posts: 694
- Joined: Tue Dec 18, 2007 3:09 pm
- Full Name: Gael Fraiteur
- Company: postsharp.org
Re: Using post sharp with web projects?
having problem uploading the solution. but it only consist of two projects with a file in each. i'll paste the content for you to look over.
*******WEB SERVICE CODE BEHIND********
using
System;
using
System.Web;
using
System.Collections;
using
System.Collections.Generic;
using
System.Web.Services;
using
System.Web.Services.Protocols;
using
System.Threading;
///
<summary> Summary description for PermService
///
</summary>
[
WebService(Namespace = "PostSharpTest")]WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public
class AdminService : System.Web.Services.WebService
{
public AdminService()//Uncomment the following line if using designed components
//InitializeComponent();
}
[
WebMethod]Required]public string Test()return new PsTester().ReturnString();
public
class PsTester
{
[
Required]public string ReturnString()return "PsTester.ReturnString()"; System; System.Collections.Generic; System.Text; System.Reflection; PostSharp.Laos; PostSharp.Extensibility;Serializable] sealed class RequiredAttribute : OnMethodBoundaryAspect/// <summary>/// Initializes the current object. Called at compile time by PostSharp./// </summary>/// <param name="field">Field to which the current instance is/// associated.</param>public override void CompileTimeInitialize(MethodBase method)/// <summary>/// Method executed <b>before</b> the body of methods to which this aspect is applied./// We just trace and increment indentation./// </summary>/// <param name="eventArgs">Event arguments specifying which method/// is being executed and which are its arguments.</param>public override void OnEntry(MethodExecutionEventArgs context)//context.FlowBehavior = FlowBehavior.Return;/// <summary>/// Method executed <b>after</b> the body of methods /// to which this aspect is applied, when the method succeeds./// </summary>/// <param name="eventArgs">Event arguments specifying which method/// is being executed and which are its arguments.</param>public override void OnSuccess(MethodExecutionEventArgs eventArgs)/// <summary>/// Method executed <b>after</b> the body of methods /// to which this aspect is applied, when the method ends with an exception./// </summary>/// <param name="eventArgs">Event arguments specifying which method/// is being executed and which are its arguments.</param>public override void OnException(MethodExecutionEventArgs eventArgs)
- dawginlife
- Posts: 6
- Joined: Sat Jan 12, 2008 4:55 pm
Re: Using post sharp with web projects?
Second Try.
having problem uploading the solution. but it only consist of two projects with a file in each. i'll paste the content for you to look over.
*******WEB SERVICE CODE BEHIND********
using System;
using System.Web;
using System.Collections;
using System.Collections.Generic;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Threading;
/// <summary>
/// Summary description for PermService
/// </summary>
[WebService(Namespace = "PostSharpTest")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class AdminService : System.Web.Services.WebService
{
public AdminService()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
[Required]
public string Test()
{
return new PsTester().ReturnString();
}
}
public class PsTester
{
[Required]
public string ReturnString()
{
return "PsTester.ReturnString()";
}
}
********CUSTOM ATTRIBUTE*******
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using PostSharp.Laos;
using PostSharp.Extensibility;
[Serializable]
public sealed class RequiredAttribute : OnMethodBoundaryAspect
{
/// <summary>
/// Initializes the current object. Called at compile time by PostSharp.
/// </summary>
/// <param name="field">Field to which the current instance is
/// associated.</param>
public override void CompileTimeInitialize(MethodBase method)
{
}
/// <summary>
/// Method executed <b>before</b> the body of methods to which this aspect is applied.
/// We just trace and increment indentation.
/// </summary>
/// <param name="eventArgs">Event arguments specifying which method
/// is being executed and which are its arguments.</param>
public override void OnEntry(MethodExecutionEventArgs context)
{
//context.FlowBehavior = FlowBehavior.Return;
}
/// <summary>
/// Method executed <b>after</b> the body of methods
/// to which this aspect is applied, when the method succeeds.
/// </summary>
/// <param name="eventArgs">Event arguments specifying which method
/// is being executed and which are its arguments.</param>
public override void OnSuccess(MethodExecutionEventArgs eventArgs)
{
}
/// <summary>
/// Method executed <b>after</b> the body of methods
/// to which this aspect is applied, when the method ends with an exception.
/// </summary>
/// <param name="eventArgs">Event arguments specifying which method
/// is being executed and which are its arguments.</param>
public override void OnException(MethodExecutionEventArgs eventArgs)
{
}
}
- dawginlife
- Posts: 6
- Joined: Sat Jan 12, 2008 4:55 pm
Re: Using post sharp with web projects?
Sorry, the address was [url=ftp://www.postsharp.org/upload/.]ftp://www.postsharp.org/upload/.[/url]
Really, please upload the projects and describe the problem because it takes a stupid time to recompose the projects and guess what is wrong.
Thank you.
Really, please upload the projects and describe the problem because it takes a stupid time to recompose the projects and guess what is wrong.
Thank you.
Gael Fraiteur, project leader
got good support? consider donating to the project.
got good support? consider donating to the project.
- gfraiteur
- Site Admin
- Posts: 694
- Joined: Tue Dec 18, 2007 3:09 pm
- Full Name: Gael Fraiteur
- Company: postsharp.org
Re: Using post sharp with web projects?
no problem, i understand.
The problem seems to be that the PostSharp does not get invoked when building an asp.net project.
I've uploaded the file is called TestPostSharp.zip.
when you start the web project, the web service will provide you with two method: HelloWorld and SaySomethingSmart. Both will return the greetings "Hello World".
The problem is the HelloWorld method does not invoke the PostSharp attribute that was created in the asp.net project. When running in debug mode, the breakpoints in this attribute "PermRequired" does not get triggered.
Method SaySomethingSmart invokes a method from a none asp.net project decorated with an attribute, "Smart" that does get triggered.
The problem seems to be that the PostSharp does not get invoked when building an asp.net project.
I've uploaded the file is called TestPostSharp.zip.
when you start the web project, the web service will provide you with two method: HelloWorld and SaySomethingSmart. Both will return the greetings "Hello World".
The problem is the HelloWorld method does not invoke the PostSharp attribute that was created in the asp.net project. When running in debug mode, the breakpoints in this attribute "PermRequired" does not get triggered.
Method SaySomethingSmart invokes a method from a none asp.net project decorated with an attribute, "Smart" that does get triggered.
- dawginlife
- Posts: 6
- Joined: Sat Jan 12, 2008 4:55 pm
Re: Using post sharp with web projects?
Excellent point.
The reason is that the build process bypasses the normal MSBuild process, where PostSharp is inserted.
I will have to look at this in details, it can take a while.
Gael
The reason is that the build process bypasses the normal MSBuild process, where PostSharp is inserted.
I will have to look at this in details, it can take a while.
Gael
Gael Fraiteur, project leader
got good support? consider donating to the project.
got good support? consider donating to the project.
- gfraiteur
- Site Admin
- Posts: 694
- Joined: Tue Dec 18, 2007 3:09 pm
- Full Name: Gael Fraiteur
- Company: postsharp.org
Re: Using post sharp with web projects?
It's not a pressing issue. I just wanted to know if i needed to reorganize my project to use PostSharp or wait for the fix. Knowing that it could take sometime, I'll just go on to plan B. FYI, PostSharp/Laos rocks; it's a lot better than the other .NET AOP frameworks i've looked at. Thanks for creating this great tool.
- dawginlife
- Posts: 6
- Joined: Sat Jan 12, 2008 4:55 pm
Re: Using post sharp with web projects?
It seems that ASP.NET compiles using CodeDom. For instance, C# files are built using Microsoft.CSharp.CSharpCodeProvider. A solution would be to "subclass" these providers to execute PostSharp at the end. I think it's feasible, but
1) It's too big to put this in scope of the version 1.0.
2) This would quite significantly slow down the process of starting up the web server, since PostSharp is many times slower than the C# compiler itself.
But if you are brave go for it
Gael
1) It's too big to put this in scope of the version 1.0.
2) This would quite significantly slow down the process of starting up the web server, since PostSharp is many times slower than the C# compiler itself.
But if you are brave go for it
Gael
Gael Fraiteur, project leader
got good support? consider donating to the project.
got good support? consider donating to the project.
- gfraiteur
- Site Admin
- Posts: 694
- Joined: Tue Dec 18, 2007 3:09 pm
- Full Name: Gael Fraiteur
- Company: postsharp.org
Re: Using post sharp with web projects?
This does not sound like a simple task; and i've not done any work with IL. (Are there any good resources for getting up to speed with IL?) as such, i'm unlikely to tackle this unless i'm provided with a good supply of painkillers.
Thanks for the update.
Thanks for the update.
- dawginlife
- Posts: 6
- Joined: Sat Jan 12, 2008 4:55 pm
25 posts • Page 1 of 3 • 1, 2, 3