Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 185601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:29:56+00:00 2026-05-11T15:29:56+00:00

I’m building a notification framework and for that I’m serializing and deserializing a basic

  • 0

I’m building a notification framework and for that I’m serializing and deserializing a basic class, from which all the classes I want to send will derive.

The problem is that the code compiles, but when I actually try to serialize this basic class I get an error saying

System.Runtime.Serialization.SerializationException: Type ‘Xxx.DataContracts.WQAllocationUpdate’ in Assembly ‘Xxx.DataContract, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’ is not marked as serializable.

Here is the code :

public class WCallUpdate : NotificationData {     private string m_from = '';     [DataMember]     public string From     {         get { return m_from; }         set { m_from = value; }     }     private WCall m_wCall = new WCall();     [DataMember]     public WCall Call     {         get { return m_wCall; }         set { m_wCall = value; }     } } 

The DataContract for the Notification is:

/// <summary> /// Basic class used in the notification service /// </summary> [DataContract] public class NotificationData { }  /// <summary> /// Enum containing all the events used in the application /// </summary> [DataContract] public enum NotificationTypeKey {     [EnumMember]     Default = 0,     [EnumMember]     IWorkQueueServiceAttributionAddedEvent = 1,     [EnumMember]     IWorkQueueServiceAttributionUpdatedEvent = 2,     [EnumMember]     IWorkQueueServiceAttributionRemovedEvent = 3, } 

The code used to serialize the data is:

    #region Create Message     /// <summary>     /// Creates a memoryStream from a notificationData     /// note: we insert also the notificationTypeKey at the beginning of the     /// stream in order to treat the memoryStream correctly on the client side     /// </summary>     /// <param name='notificationTypeKey'></param>     /// <param name='notificationData'></param>     /// <returns></returns>     public MemoryStream CreateMessage(NotificationTypeKey notificationTypeKey, NotificationData notificationData)     {         MemoryStream stream = new MemoryStream();         BinaryFormatter formatter = new BinaryFormatter();         try         {             formatter.Serialize(stream, notificationTypeKey);             formatter.Serialize(stream, notificationData);         }         catch (Exception ex)         {             Logger.Exception(ex);         }         return stream;     }     #endregion 

When I try to create a message:

WCallUpdate  m_wCallUpdate = new WCallUpdate(); NotificationTypeKey  m_notificationTypeKey = new NotificationTypeKey.Default; CreateMessage(notificationTypeKey , wCallUpdate ); 

I got the following error:

System.Runtime.Serialization.SerializationException: Type 'Xxx.DataContracts.WCall' in Assembly 'Xxx.DataContract, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.    at System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type)    at System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context)    at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo()    at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter)    at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter)    at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo)    at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)    at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)    at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph)    at Xxx.Notification.NotificationMessageFactory.CreateMessage(NotificationTypeKey notificationTypeKey, NotificationData notificationData) in Xxx.Notification\NotificationCenter.cs:line 36 

If I put the Serializable flag before the DataContract one does not solve the problem.


thank you for the fast answer. Sorry that i forgot to put the code of the NotificationData (edited in the main post)

I tried putting the Serializable attribute to both class without success 🙁

#region NotificationData /// <summary> /// Basic class used in the notification service /// </summary> [Serializable] [DataContract] public class NotificationData { } #endregion 

and

[Serializable] public class WCallUpdate : NotificationData {     private string m_from = '';     [DataMember]     public string From     {         get { return m_from; }         set { m_from = value; }     }     private WCall m_wCall = new WCall();     [DataMember]     public WCall Call     {         get { return m_wCall; }         set { m_wCall = value; }     } } 

**Edit: ** Mea culpa afterall 🙂 You were both right. I forgot to spread the [Serializable] Attribute to all the child class. After updating and compiling, i got no longer the exception. thank you both for your correct answers 🙂


@Marc Gravel: Actually i thought about what you are suggesting, and created the following DataContractSerializer, but I’m not sure this will work? As my classes use other classes? the big problem with the DataContractSerializer is that you need to specify the type of the object you want to serialize, and as my class uses other class as private fields, that might cause a problem right?

#region DataContractSerializer         /// <summary>         /// Creates a Data Contract Serializer for the provided type. The type must be marked with         /// the data contract attribute to be serialized successfully.         /// </summary>         /// <typeparam name='T'>The type to be serialized</typeparam>         /// <returns>A data contract serializer</returns>         public static DataContractSerializer CreateDataContractSerializer<T>() where T : class         {             DataContractSerializer serializer = new DataContractSerializer(typeof(T));             return serializer;         }         #endregion 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T15:29:56+00:00Added an answer on May 11, 2026 at 3:29 pm

    put [Serializable] at the top of the class. Serializable isn’t necessarily inherited either AFAIK. meaning even if the base class has [Serializable], you still need it on the descendent class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 119k
  • Answers 119k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I find it surprising that it's so hard to remove.… May 11, 2026 at 11:48 pm
  • Editorial Team
    Editorial Team added an answer AFAIK, the regular licence for VS is for the user,… May 11, 2026 at 11:48 pm
  • Editorial Team
    Editorial Team added an answer The best way to improve the performance of resizing is,… May 11, 2026 at 11:48 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.