This question may be very similar to my one, but I cannot see the answer I need in it. I have a class, called CASM
, that has a List<Action>
. I want to serialize this class (using the BinaryFormatter
or something similar). This class and all classes referenced in the Action
s have got correct [Serializable]
and [NonSerializable]
attributes.
The problem comes when serialization is attempted - it gives this error:
Type 'CASM.CASM+<>c__DisplayClass2c' in Assembly 'CASM, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null' is not marked as serializable.
This <>c__DisplayClass2c
is an autogenerated internal class that holds the different types of anonymous delegate I am using in my application. However, as we can see from the below image, it is not [Serializable]
:
What would be the best way to change my application so this does work? Make my own <>c__DisplayClass2c
-type class and make it serializable? Or is there a better way?
EDIT: In the end I just made my own class, instead of the autogenerated one. I helps with debugging as well, actually having a descriptive name rather than just b__12()
.