首页 > 解决方案 > System.InvalidProgramException:公共语言运行时检测到无效程序

问题描述

全部,

我正在使用 ZeroFormatter 对大对象进行序列化,有时在序列化错误时会出现以下错误,在使用 ZeroFormatter 的 Union 概念进行继承后会观察到此问题。

以下是异常详细信息:

System.InvalidProgramException:公共语言运行时检测到无效程序。
在 ZeroFormatter.DynamicObjectSegments.ZeroFormatter_Formatters_DefaultResolver.Colibrium.Common.Ontology.Rating.Factors.RateFactor$Formatter.Serialize(Byte[]& , Int32 , RateFactor )
在 ZeroFormatter.Formatters.CollectionFormatter 3.Serialize(Byte[]& bytes, Int32 offset , TCollection 值) 在 ZeroFormatter.DynamicObjectSegments.ZeroFormatter_Formatters_DefaultResolver.Colibrium.Common.Ontology.Rating.PackagePlan$Formatter.Serialize(Byte[]& , Int32 , PackagePlan ) 在 ZeroFormatter.Formatters.CollectionFormatter 3.Serialize(Byte[]& bytes, Int32 偏移量,TCollection 值)3.Serialize(Byte[]& bytes, Int32 offset, TCollection value)
at ZeroFormatter.DynamicObjectSegments.ZeroFormatter_Formatters_DefaultResolver.Colibrium.Common.Ontology.Rating.RateClass$Formatter.Serialize(Byte[]& , Int32 , RateClass )
at ZeroFormatter.Formatters.CollectionFormatter


3.Serialize(Byte[]& bytes, Int32 offset, TCollection value)
at ZeroFormatter.DynamicObjectSegments.ZeroFormatter_Formatters_DefaultResolver.Colibrium.Common.Ontology.Rating.Package$Formatter.Serialize(Byte[]& , Int32 , Package )
at ZeroFormatter.Formatters.CollectionFormatter

在 ZeroFormatter.DynamicObjectSegments.ZeroFormatter_Formatters_DefaultResolver.Colibrium.Common.Ontology.Rating.PackageGroup$Formatter.Serialize(Byte[]& , Int32 , PackageGroup )
在 ZeroFormatter.Formatters.CollectionFormatter 1.Serialize[T](T obj) 在 Colibrium.Utility .Library.ObjectConverter`1.ConvertO bjectToBinaryZeroFormatter(T p_object)3.Serialize(Byte[]& bytes, Int32 offset, TCollection value)
at ZeroFormatter.DynamicObjectSegments.ZeroFormatter_Formatters_DefaultResolver.Colibrium.Common.Ontology.Rating.Group.GroupRatingResults$Formatter.Serialize(Byte[]& , Int32 , GroupRatingResults )
at ZeroFormatter.ZeroFormatterSerializer.CustomSerializer

在 C:\TFS\UPMC\Repos\Colibrium.Utility.Library\ObjectConverter.cs:407 行

标签: serializationclrzeroformatter

解决方案


查看DynamicFormatter的源代码,似乎该库试图通过在运行时生成 CLR 类型来将用户类型序列化/反序列化为字节数组来优化用户类型的格式。根据错误,这代 IL 似乎一定存在错误。

您应该在ZeroFormatter 项目问题中报告此问题,但请注意,您可能需要有一个重现此问题的好方法,因为追踪一个InvalidProgramException非常具有挑战性。


推荐阅读