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 1010633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T09:06:48+00:00 2026-05-16T09:06:48+00:00

On my WPF application, I am using DataContractSerializer to serialize object. I observed that

  • 0

On my WPF application, I am using DataContractSerializer to serialize object. I observed that it fails to serialize the types that has got an event or delegate declaration. Consider the following failing code:

[Serializable]
public abstract class BaseClass
{
    public string Name { get; set; }

    public event PropertyChangedEventHandler PropertyChanged;
}

public class DerivedClass : BaseClass
{
    public int Age { get; set; }
}


class Program
{
    static void Main(string[] args)
    {
        DerivedClass derivedClass = new DerivedClass {Name = "Test", Age = 10};
        derivedClass.PropertyChanged += (sender, eventArgs) => Console.WriteLine("hello");

        DataContractSerializer serializer  = new DataContractSerializer(typeof(DerivedClass));
        using(FileStream stream = new FileStream("c:\\test.txt", FileMode.Create, FileAccess.ReadWrite))
        {
            serializer.WriteObject(stream, derivedClass);
        }     
    }
}

This fails with message

Type
‘System.DelegateSerializationHolder+DelegateEntry’
with data contract name
‘DelegateSerializationHolder.DelegateEntry:http://schemas.datacontract.org/2004/07/System‘
is not expected. Add any types not
known statically to the list of known
types – for example, by using the
KnownTypeAttribute attribute or by
adding them to the list of known types
passed to DataContractSerializer.

I tried to add attributes like [DataMember(IsRequired = false)] on the event to indicate that it should not be serialized, but nothing worked.

Everything worked when I removed the [Serializable] attribute from the BaseClass. I am wondering why this behavior? Is it safe to avoid giving [Serializable] attribute?

.NET framework version : 3.5 SP1

  • 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. Editorial Team
    Editorial Team
    2026-05-16T09:06:49+00:00Added an answer on May 16, 2026 at 9:06 am
    [field:NonSerialized]
    public event PropertyChangedEventHandler PropertyChanged;
    

    This tells the DataContractSerializer, “don’t serialize the auto-generated EventHandlerList field for this event”. Thus, any object instances attached to your event won’t be considered part of the object graph being serialized.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You are getting the error because you need to call… May 16, 2026 at 5:41 pm
  • Editorial Team
    Editorial Team added an answer You don't actually have a circular reference; the issue is… May 16, 2026 at 5:41 pm
  • Editorial Team
    Editorial Team added an answer You can use your VC++ 2010 prq file and just… May 16, 2026 at 5:41 pm

Trending Tags

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

Top Members

Related Questions

I've got small wpf application deployed using ClickOnce technology. The problem is that when
I'm creating a WPF application using the MVVM design pattern that consists of a
I am using MVVM architecture to develop a WPF application... So far everything has
I am creating a WPF Application using VS 2005. I download the add on
I have a WPF application using Aero Glass. When using the application under a
I am installing a WPF Application using the ClickOnce deployment. There are certain settings
I'm developing a WPF application using the MVVM pattern and I need to display
I'm writting an WPF application using the mvvm toolkint. In the main windows I
In a WPF Application using XAML, I created a stackpanel(width 1030) and I have
In a WPF Application using XAML, I have 2 images, which needs to be

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.