postsha:OnMethodBoundaryAspect 和 WebMethod

发布于 2024-10-03 15:29:54 字数 868 浏览 0 评论 0原文

我正在使用 PostSharp 向 WebMethod 添加一个方面。

下面是我的方面(它什么都不做...不想编译):

public class MyAspect : OnMethodBoundaryAspect, ISerializable
{
    public override void OnException(MethodExecutionEventArgs eventArgs)
    {

    }

    public override void OnEntry(MethodExecutionEventArgs eventArgs)
    {

    }

    public void GetObjectData(SerializationInfo info, StreamingContext context)
    {

    }
}

我的 webmethod 看起来像:

    [MyAspect]
    [WebMethod]
    public void MyWebMethod()
    {
        //...
    }

当我构建项目时,出现错误:

Erreur 346 PostSharp:无法序列化方面: Le type 'xxxx. MyAspect' dans l' assembly 'zzzzz, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' n'est pas marqué comme sérialisable..unknown_location xxxxx

它告诉我我的方面没有标记为可序列化...

什么可以我愿意?仅供参考,我在项目的其余部分中对这些方面没有任何问题。

I'm using PostSharp to add an aspect to a WebMethod.

Below is my aspect (it does nothing... doesn't want to compile):

public class MyAspect : OnMethodBoundaryAspect, ISerializable
{
    public override void OnException(MethodExecutionEventArgs eventArgs)
    {

    }

    public override void OnEntry(MethodExecutionEventArgs eventArgs)
    {

    }

    public void GetObjectData(SerializationInfo info, StreamingContext context)
    {

    }
}

And my webmethod looks like :

    [MyAspect]
    [WebMethod]
    public void MyWebMethod()
    {
        //...
    }

When I build the project, there is an error:

Erreur 346 PostSharp: Cannot serialize the aspects: Le type 'xxxx.MyAspect' dans l'assembly 'zzzzz, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' n'est pas marqué comme sérialisable.. unknown_location xxxxx

It tells me that my aspect is not tagged as serializable...

What can I do? FYI, I don't have any problem with such aspects in the rest of the project.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

与他有关 2024-10-10 15:29:54

您应该将 Serializable 属性添加到 MyAspect 中。所以:

[Serializable]
public class MyAspect : OnMethodBoundaryAspect

而不是继承ISerialized接口。有关差异,请参阅此问题

You should add the Serializable attribute to your MyAspect. So:

[Serializable]
public class MyAspect : OnMethodBoundaryAspect

Instead of inheriting the ISerializable interface. For the differences see this question.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文