PostSharp
最近、箱から出してすぐに使えると思われる驚くべき AOP フレームワークを発見しました。すべてが順調で、共有ホストにアプリケーションをアップロードすることを決定するまで、log4net を使用してカスタム ロギングの側面も実装しました。
共有ホストでは機能しません。カスタム アスペクトが使用されているページで、次のエラーが発生します。
Sorry, an error occurred while processing your request.
PostSharp を共有ホスティングで動作させるために微調整が必要なものがあるかどうかを知りたいですか?
また、取得しているメッセージがまったく役に立たないために失敗したページでスローされる有用な例外メッセージを取得するにはどうすればよいですか?
私の側面は次のとおりです。
[Serializable]
public class LoggingAspect : OnMethodBoundaryAspect
{
//Here is the once-per-class call to initialize the log object
//[NonSerialized]
//private static readonly ILog log = LogManager.GetLogger("Logger");
private string methodName;
private string className;
private Type declaringType;
/// <summary>
/// Method executed at build time. Initializes the aspect instance. After the execution
/// of <see cref="CompileTimeInitialize"/>, the aspect is serialized as a managed
/// resource inside the transformed assembly, and deserialized at runtime.
/// </summary>
/// <param name="method">Method to which the current aspect instance
/// has been applied.</param>
/// <param name="aspectInfo">Unused.</param>
public override void CompileTimeInitialize(MethodBase method, AspectInfo aspectInfo)
{
this.methodName = method.Name;
this.className = method.DeclaringType.FullName;
this.declaringType = method.DeclaringType;
}
/// <summary>
/// Method invoked before the execution of the method to which the current
/// aspect is applied.
/// </summary>
/// <param name="args">Information about the method being executed.</param>
public override void OnEntry(MethodExecutionArgs args)
{
//log.Debug(this.className + "." + this.methodName + ": Enter");
}
/// <summary>
/// Method invoked after successfull execution of the method to which the current
/// aspect is applied.
/// </summary>
/// <param name="args">Information about the method being executed.</param>
public override void OnSuccess(MethodExecutionArgs args)
{
//log.Debug(this.className + "." + this.methodName + ": Success");
}
/// <summary>
/// Method invoked after failure of the method to which the current
/// aspect is applied.
/// </summary>
/// <param name="args">Information about the method being executed.</param>
public override void OnException(MethodExecutionArgs args)
{
//log.Error(this.className + "." + this.methodName + ": Exception " + args.Exception.Message);
}
}
ご覧のとおり、問題が log4net によるものではないことを証明するために、log4net を使用してすべての行をコメントアウトしました。log4net を含めると、PostSharp を機能させた後に解決するために保存した他の問題を実行できます。したがって、空のメソッドだけでも PostSharp は機能しません。誰かがここに欠けているものを指摘できますか?
PostSharp と log4net の両方が、デバッグ モードの localhost でうまく機能することを付け加えたいと思います。エラーは発生せず、問題は共有ホスティングでのみ発生します。
アップデート
customErrors
mode
属性をoff
inに設定して、同じコードをもう一度試しましたweb.config
。次の例外が発生します。
Exception Details: System.Security.SecurityException: Request failed.
Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.
Exception Details: System.Security.SecurityException: Request failed.
Stack Trace:
[SecurityException: Request failed.]
PostSharp.Aspects.Serialization.BinaryAspectSerializer..cctor() +0
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18055
Trust
これは、アプリケーションのレベルを変更するには、共有ホスティング プロバイダーに連絡する必要があるということですか? この問題の回避策があることを願っていますか?