Post -Shap: Onmethodboundaryaspect und WebMethod
-
27-09-2019 - |
Frage
Ich verwende Postsharp, um einem WebMethod einen Aspekt hinzuzufügen.
Unten ist mein Aspekt (es tut nichts ... will nicht kompilieren):
public class MyAspect : OnMethodBoundaryAspect, ISerializable
{
public override void OnException(MethodExecutionEventArgs eventArgs)
{
}
public override void OnEntry(MethodExecutionEventArgs eventArgs)
{
}
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
}
}
Und mein WebMethod sieht aus wie:
[MyAspect]
[WebMethod]
public void MyWebMethod()
{
//...
}
Wenn ich das Projekt erstelle, gibt es einen Fehler:
Erreur 346 Postsharp: Die Aspekte können nicht serialisieren: le Typ 'xxxx.myaspect' Dans l' -Assembly 'Zzzzz, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null' n'est pas marqué comme sérialisable .. unbekannt_location xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.
Es sagt mir, dass mein Aspekt nicht als serialisierbar markiert ist ...
Was kann ich machen? Zu Ihrer Information, ich habe im Rest des Projekts kein Problem mit solchen Aspekten.
Lösung
Sie sollten die hinzufügen Serializable
Attribut auf dein MyAspect
. So:
[Serializable]
public class MyAspect : OnMethodBoundaryAspect
Anstatt die zu erben ISerializable
Schnittstelle. Für die Unterschiede siehe diese Frage.