0

我已经构建了一个方面,它使用我自己的一个库中的一个类来完成它的工作。该类需要被序列化才能有用,但是当让 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.

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

ps 该类的定义如下所示:

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

- 更新 -

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

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

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

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

4

1 回答 1

7

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

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

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

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

因为第二种方法更困难,所以[Serializable]如果您的项目以 .NET 而不是 Silverlight、Windows Store 或 Windows Phone 为目标,则使用普通的 .NET 序列化程序可能是一个更好的主意。

于 2013-09-06T06:05:40.253 回答