找不到类型的序列化程序

ekk*_*kis 0 .net vb.net aop postsharp

我已经构建了一个方面,它使用我自己的库中的一个类来工作。为了有用,该类需要可序列化,但是当让 PostSharp 做它的事情时,我收到了这个错误:

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.
Run Code Online (Sandbox Code Playgroud)

有谁知道我可能会错过什么?

ps 该类的定义如下所示:

Namespace NextGen.Framework.Managers.LogMgr
    <Serializable>
    Public Class NxLogMgr
Run Code Online (Sandbox Code Playgroud)

- 更新 -

在谷歌搜索中,我确实发现了这个(来自 PostSharp 开发人员):

当您尝试在方面内序列化类型时会发生这种情况,并且 CLR 无法将类型加载为运行时类型。PostSharp 然后提供反射包装器,但这些不能被序列化

(参见:http : //support.sharpcrafters.com/discussions/problems/484-additional-exception-detail

所以我的方面使用这个 LogMgr 类,它被声明为可序列化,但为什么不能被 CLR 加载?

Gae*_*eur 6

您收到此消息是因为您标记了一个类型,[PSerializable]并且该类型具有一个没有序列化程序的类型的可序列化字段(未标记为[PNonSerialized])。有两种可用的策略:

  • 将类型标记NextGen.Framework.Managers.LogMgr.NxLogMgr[PSerializable],它会为此类型生成标准序列化程序。如果您拥有该程序集的源代码并且能够在其上运行 PostSharp,这可能是最佳选择。

  • 为这种类型编写自定义序列化程序:

    1. PostSharp.Serialization.ReferenceTypeSerializer或派生类型PostSharp.Serialization.ValueTypeSerializer并实现抽象方法。
    2. 将自定义属性添加PostSharp.Serialization.ImportSerializerAttribute到程序集或引用NextGen.Framework.Managers.LogMgr.NxLogMgr.

因为第二种方法更难,[Serializable]如果您的项目无论如何都面向 .NET 而不是 Silverlight、Windows Store 或 Windows Phone,那么使用普通的 .NET 序列化程序可能是一个更好的主意。