0

Encountered VerificationException "Operation could destabilize runtime" error using MsgPack to serialize some F# types. The compiler also suggests that conflicting class libraries may be loaded, but this appears to be a red herring.

It's not immediately clear what the error is caused by, so posting the solution below for community benefit.


In response to Comments below:

....Sammo\bin\Debug>peverify /verbose Sammo.exe

Microsoft (R) .NET Framework PE Verifier.  Version  4.0.30319.17929
Copyright (c) Microsoft Corporation.  All rights reserved.

All Classes and Methods in Sammo.exe Verified.



....Sammo\bin\Debug>Sammo.exe
Unhandled Exception: System.Security.VerificationException: Operation could destabilize the runtime.
   at _4(MsgPackReader )
   at _3(MsgPackReader )
   at MsgPack.CompiledPacker.Unpack[T](Stream strm)
   at MsgPack.CompiledPacker.Unpack[T](Byte[] buf, Int32 offset, Int32 size)
   at MsgPack.CompiledPacker.Unpack[T](Byte[] buf)
   at <StartupCode$Sammo>.$Program.main@() in ....\Sammo\Pro
gram.fs:line 67

....\Sammo\bin\Debug>
Anthony
  • 1,306
  • 4
  • 13
  • 23
  • 2
    Can you run `peverify --verbose` on your compiled assembly and post the results here (if there are any errors)? (If you haven't used `peverify` before, you need to run it from the Visual Studio command prompt instead of the normal command prompt). – Jack P. Mar 13 '13 at 14:06

1 Answers1

0

The problem is that MsgPack, a serialization library does not support particular DateTime formats or conventions.

The error message output is misleading however, and it's only when you dig deeper into the Exception that you can find more clues about what is going on.

As an alternative solution, one can instead use a Unix timestamp or the .Net Ticks [100ns] concept for the underlying value/field with an appropriate member definition to expose a System.DateTime.

Anthony
  • 1,306
  • 4
  • 13
  • 23
  • Hmm, DateTime is not a template and it is not an attribute. A very simple type, it hasn't changed since .NET 1.0. It doesn't sound like you identified the real problem. – Hans Passant Mar 13 '13 at 12:26
  • I'm afraid I haven't stated the problem clearly enough - the problem is that MsgPack library doesn't support serializing the System.DateTime type, but I suppose the error produced by VisStudio is a little misleading and could be worth following up. – Anthony Mar 13 '13 at 16:40