0

I recently wrote a code for copying a class with C5 library "IntervalHeap" but encountered an error message like this.

System.Runtime.Serialization.SerializationException: 'Type 'C5.IntervalHeap`1+Interval[[TransSys1.Node, TransSys1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' in Assembly 'C5, Version=2.5.0.0, Culture=neutral, PublicKeyToken=282361b99ded7e8e' is not marked as serializable.'

I checked the source code in here but the IntervalHeap class is already labeled as [Serializable]. I built the source code again but it still not working. I debugged my project with x64 platforms.

Can you let me know what are the potential reasons or how to solve it?

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Thomas J
  • 35
  • 9
  • Possible duplicate of [SerializationException Type "is not marked as serializable" - But it is](https://stackoverflow.com/questions/11507819/serializationexception-type-is-not-marked-as-serializable-but-it-is) – orhtej2 Sep 02 '18 at 20:35
  • @orhtej2, It doesn't seem to be a duplicate to that question: that question related to `partial class` and `Form`, this assembly and type is neither of those https://github.com/sestoft/C5/blob/master/C5/heaps/IntervalHeap.cs the answer may be of consideration, but not apparent enough to relate it as a duplicate. – Brett Caswell Sep 02 '18 at 20:52
  • Thomas, gives us a code sample of the class you wrote that 'copies' (which I presume you mean inherits) this `IntervalHeap` class. – Brett Caswell Sep 02 '18 at 21:03
  • more importantly, thomas, what are you passing as the generic `T`? if it is a class, is it marked as `serializable`? can you try that real quick, – Brett Caswell Sep 02 '18 at 21:06

1 Answers1

1

The exception message points to the Interval struct, defined as inner struct within C5.IntervalHeap<T> noted as

C5.IntervalHeap`1+Interval

You get this error because this Interval struct is not marked Serializable.

Unless you own that source (maybe via a copy) there isn't much you can do about it.
Maybe find another way to take a copy, without serializing.

pfx
  • 20,323
  • 43
  • 37
  • 57
  • hmm.. you have enough rep to know the difference between a comment and answer, so why are you point at the exception as being the answer? – Brett Caswell Sep 02 '18 at 20:57
  • I read in OP's question: what are the potential reasons. Going to explain further what to do. – pfx Sep 02 '18 at 20:59
  • you're saying the potential reason for the exception is that a struct (a value type) should be marked as `serializable`? you don't think perhaps it is the generic `T` referenced in the structure? – Brett Caswell Sep 02 '18 at 21:01
  • At this point it fails at the `Interval` struct as the error states: Type C5.IntervalHeap`1+Interval, which is the notation to an inner struct/class. – pfx Sep 02 '18 at 21:04