System.InvalidProgramException: Common Language Runtime detected an invalid program

2.7k views Asked by At

All,

I am using ZeroFormatter for serialization of a big object, sometimes it is giving following error while serializing the error, this issue is observed after using Union concept of ZeroFormatter for inheritence.

Here are the exception details:

System.InvalidProgramException: Common Language Runtime detected an invalid program.
at ZeroFormatter.DynamicObjectSegments.ZeroFormatter_Formatters_DefaultResolver.Colibrium.Common.Ontology.Rating.Factors.RateFactor$Formatter.Serialize(Byte[]& , Int32 , RateFactor )
at ZeroFormatter.Formatters.CollectionFormatter3.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.PackagePlan$Formatter.Serialize(Byte[]& , Int32 , PackagePlan )
at ZeroFormatter.Formatters.CollectionFormatter3.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
3.Serialize(Byte[]& bytes, Int32 offset, TCollection value)
at ZeroFormatter.DynamicObjectSegments.ZeroFormatter_Formatters_DefaultResolver.Colibrium.Common.Ontology.Rating.PackageGroup$Formatter.Serialize(Byte[]& , Int32 , PackageGroup )
at ZeroFormatter.Formatters.CollectionFormatter3.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
1.Serialize[T](T obj)
at Colibrium.Utility.Library.ObjectConverter`1.ConvertO bjectToBinaryZeroFormatter(T p_object)

in C:\TFS\UPMC\Repos\Colibrium.Utility.Library\ObjectConverter.cs:line 407

2

There are 2 answers

0
codekaizen On

Looking at the source code for DynamicFormatter it appears the library tries to optimize formatting of your user types by generating CLR types at runtime to serialize / deserialize the user type to a byte array. Based on the error, it seems there must be a bug in this IL generation.

You should report this problem in the ZeroFormatter project issues but note you will likely need to have a good way to reproduce this issue, as tracking down an InvalidProgramException is very challenging.

0
user232548 On

In case you happen to have Application Insights in use, the exception may be thrown due to issue 18323 reported to .Net Core CRL

The issue is reported on .Net core, but I have also reported it on .Net Framework due to the solution seeming to work also there.

ApplicationInsights has moved towards a Preinstalled Site Extension model and does not have the offending bits anymore. In addition, the private Site Extension will not be updated as it is estimated to be deprecated within a month. You should be able to upgrade to the preinstalled site extension through the ApplicationInsights configuration in the AppService blade in Azure.

However, if you want an immediate solution for the private site extension, you can workaround the issue by removing the following two files in the site extension and restarting the site:

  • Instrumentation32\ProductionBreakpoints_x86.config
  • Instrumentation64\ProductionBreakpoints_x64.config

This will effectively remove the part of AppInsights extension causing issues.