| Severity | Error |
| Reported by | PostSharp |
| Message | Aspect type "<AspectType>" must be annotated with [PSerializable]. |
Cause
PostSharp creates the aspect instances at build time and serializes them into the assembly. It uses the SerializerType of the configuration of the aspect when it is set, and otherwise the PostSharp serializer, when the aspect class has the [PSerializableAttribute] attribute.
When the aspect class has neither, PostSharp checks whether the target framework of the project supports the binary serialization of .NET. PostSharp reports LA0118, on the aspect class <AspectType>, when it does not: for example on .NET Standard 1.x, .NET Core 1.x, portable class libraries, UWP and Xamarin. On .NET Framework, .NET Standard 2.0 and later, and .NET Core 2.0 and later, PostSharp reports LA0119 instead.
This message depends on a target framework that the test projects of this documentation do not target, so no example can show it. LA0119 shows the same mistake on .NET.
Resolution
- Add [PSerializableAttribute] to the aspect class. Mark the fields that must not be serialized with [PNonSerializedAttribute]. [SerializableAttribute] is not an option on these platforms.
- When the aspect has no state computed at build time, set the SerializerType of its configuration to MsilAspectSerializer: PostSharp then generates code that creates the aspect at run time instead of serializing it.
See Also
Reference
PSerializableAttribute
MsilAspectSerializer
SerializerType
Other Resources