Question

I've built an aspect that uses a class in one of my own libraries for its work. the class needed to be made serializable in order to be useful but when getting PostSharp to do its thing I'm getting this error:

PostSharp 3.0 [3.0.35.0, 64 bit, CLR 4.5, Release] - Copyright (c) SharpCrafters
 s.r.o., 2004-2012.

POSTSHARP : error LA0001: Cannot serialize the aspects: Cannot find a serializer
 for type 'NextGen.Framework.Managers.LogMgr.NxLogMgr'..
POSTSHARP : message PS0122: Details of the previous error or warning:\nPostSharp
.Serialization.PortableSerializationException: Cannot find a serializer for type
 'NextGen.Framework.Managers.LogMgr.NxLogMgr'.
POSTSHARP : message PS0122:    at PostSharp.Serialization.SerializationWriter.Ge
tObjectInfo(Object obj)
POSTSHARP : message PS0122:    at PostSharp.Serialization.SerializationWriter.Wr
iteObjectReference(Object value, Boolean writeInitializationDataInline)
POSTSHARP : message PS0122:    at PostSharp.Serialization.SerializationWriter.Wr
iteValue(Object value, SerializationIntrinsicType intrinsicType, Boolean writeIn
itializationDataInline)
POSTSHARP : message PS0122:    at PostSharp.Serialization.SerializationWriter.Wr
iteArguments(Arguments arguments, Boolean writeInitializationArgumentsInline)
POSTSHARP : message PS0122:    at PostSharp.Serialization.SerializationWriter.Se
rialize(Object obj)
POSTSHARP : message PS0122:    at ^RIeE65/59SwT.^AiEkYplb()
POSTSHARP : error PS0060: The processing of module "NextGen.BusinessObject.Posti
ngQueueMgr_3Base.dll-PostSharp.dll" was not successful.

does anyone know what I could be missing?

p.s. the definition for that class looks like this:

Namespace NextGen.Framework.Managers.LogMgr
    <Serializable>
    Public Class NxLogMgr

- update -

in googling I did find this (from the PostSharp developer):

it happens when you are trying to serialize a Type inside the aspect, and the Type cannot be loaded by the CLR as a Runtime Type. PostSharp then provides reflection wrappers, but these cannot be serialized

(see: http://support.sharpcrafters.com/discussions/problems/484-additional-exception-detail)

so my aspect uses this LogMgr class, which is declared as serializable, but cannot be loaded by the CLR why?

Was it helpful?

Solution

You are getting this message because you marked a type with [PSerializable] and this type has a serializable field (not marked with [PNonSerialized]) of a type for which there is no serializer. There are two strategies available:

  • Mark the type NextGen.Framework.Managers.LogMgr.NxLogMgr as [PSerializable], which generates a standard serializer for this type. This is probably the best option if you have the source code of this assembly and are able to run PostSharp on it.

  • Write a custom serializer for this type:

    1. Derive a type from PostSharp.Serialization.ReferenceTypeSerializer or PostSharp.Serialization.ValueTypeSerializer and implement abstract methods.
    2. Add a custom attribute PostSharp.Serialization.ImportSerializerAttribute to the assembly or to the type referencing the NextGen.Framework.Managers.LogMgr.NxLogMgr.

Because the second approach is more difficult, it may be a better idea to use the normal .NET serializer [Serializable] if your project anyway targets .NET and not Silverlight, Windows Store, or Windows Phone.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top