SerializationException Type “is not marked as serializable” - But it is

后端 未结 4 1310
甜味超标
甜味超标 2021-01-01 19:21

In Windows Forms, .NET Framework 4.0, I am trying to Serialize an instance of a class I wrote.

The class is marked as Serializable, but the form that uses the class

4条回答
  •  盖世英雄少女心
    2021-01-01 19:56

    This is something you can run into with any JSON serialization, including Web API in MVC 4.

    I found this post to be very helpful when I was getting a serialization except on a const int value. Any const value needs to be marked with the same attribute as in Nick Freeman's answer:

    [field: NonSerializedAttribute]
    const int iCantBeSerialized = 1;
    

提交回复
热议问题