2013-09-06 3 views
0

J'ai construit un aspect qui utilise une classe dans une de mes bibliothèques pour son travail. la classe nécessaire pour être sérialisable pour être utile, mais lors de l'obtention PostSharp à faire sa chose j'obtenir cette erreur:Impossible de trouver un sérialiseur pour le type

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. 

personne ne sait ce que je pourrais être absent?

p.s. la définition de cette classe ressemble à ceci:

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

- mise à jour -

à googler j'ai trouvé cela (le développeur PostSharp):

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

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

donc mon aspect utilise cette classe LogMgr, qui est déclarée sérialisable, mais qui ne peut pas être chargée par le CLR pourquoi?

Répondre

1

Vous recevez ce message car vous avez marqué un type avec [PSerializable] et ce type a un champ sérialisable (non marqué [PNonSerialized]) d'un type pour lequel il n'y a pas de sérialiseur. Il existe deux stratégies disponibles:

  • Marquer le type NextGen.Framework.Managers.LogMgr.NxLogMgr comme [PSerializable], qui génère un sérialiseur standard pour ce type. C'est probablement la meilleure option si vous avez le code source de cet assembly et êtes capable d'exécuter PostSharp dessus.

  • Ecrire un sérialiseur personnalisé pour ce type:

    1. dérivez un type de PostSharp.Serialization.ReferenceTypeSerializer ou PostSharp.Serialization.ValueTypeSerializer et mettre en œuvre des méthodes abstraites.
    2. Ajoutez un attribut personnalisé PostSharp.Serialization.ImportSerializerAttribute à l'assemblage ou au type référençant le NextGen.Framework.Managers.LogMgr.NxLogMgr.

Parce que la deuxième approche est plus difficile, il est peut-être une meilleure idée d'utiliser le sérialiseur .NET normale [Serializable] si votre projet cible de toute façon .NET et non Silverlight, Windows Store ou Windows Phone.

+0

cela fonctionne. oui!!! – ekkis

+0

Existe-t-il un exemple d'implémentation d'un ReferenceTypeSerializer personnalisé? La documentation est assez éparse sur ce sujet. –

Questions connexes