| Severity | Error |
| Reported by | PostSharp |
| Message | Error during aspect serialization: <Details> |
Cause
PostSharp serializes the aspects at build time and deserializes them at run time. An aspect class marked with [Serializable] instead of [PSerializable] is serialized by the BinaryAspectSerializer, which BinaryFormatter implements. This serializer does not store the reflection objects of the aspect, such as the values of its fields of type Type or MethodBase, in the serialized data: PostSharp generates code that loads them at run time.
PostSharp reports LA0131 when it cannot generate this code, and <Details> says why:
- The reflection object contains unbound generic arguments, for example a member of a generic type or a generic method that is not bound to concrete type arguments. The code that loads the reflection objects is not generic, so it cannot refer to them.
- PostSharp cannot find the reflection object in the module, or the type is invalid.
The message has no location.
This message requires the BinaryFormatter, whose use is unsupported: the build reports LA0206 for a [Serializable] aspect unless the PostSharpBinaryFormatterAllowed MSBuild property of the project is set, so no example can show the message.
Resolution
- Mark the aspect class, and the classes that it serializes, with [PSerializable] instead of
[Serializable], and remove thePostSharpBinaryFormatterAllowedproperty from the project. The PortableFormatter does not need this generated code. See BinaryFormatter Security. - If the aspect must keep the BinaryFormatter, remove the field that stores the reflection object named in
<Details>, or mark it[NonSerialized]and initialize it again at run time, for example in theRuntimeInitializemethod of the aspect.
See Also
Reference
PSerializableAttribute
BinaryAspectSerializer
Other Resources