---
title: "Do not serialize delegates and events blindly"
url: "https://osherove.com/blog/2004/12/29/do-not-serialize-delegates-and-events-blindly.md"
canonical: "https://osherove.com/blog/2004/12/29/do-not-serialize-delegates-and-events-blindly.html"
published: "2004-12-29T14:50:00"
updated: "2004-12-29T14:50:00"
tags: [".Net Original"]
author: "Roy Osherove"
description: "usually, you should not serialize your class's delegates or events. This is because serialization takes he full object graph into play, and delegates by nature will serialize your subscriber list into the mix…"
usage: "Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page)."
license: "https://creativecommons.org/licenses/by/4.0/"
---

# Do not serialize delegates and events blindly

By Roy Osherove December 29, 2004 In [.Net Original](https://osherove.com/blog/category/net-original)

**Historical article** · Originally published December 29, 2004; technical details may be outdated.

usually, you should not serialize your class's delegates or events. This is because serialization takes he full object graph into play, and delegates by nature will serialize your subscriber list into the mix (invocation list). you can never make sure all your subscribers are serializable, can you?

so, you should put \[NonSerialized\] on delegates.

on events (with the event keyword) you can use the

\[Field:NonSerialized\] attribute  ("Field" is in System.Reflection)

\[via [Juval Lowy's](http://www.idesign.net/) .Net Master class\]

## More in .Net Original

[All posts in .Net Original](https://osherove.com/blog/category/net-original)

- Dec 31, 2004

    ### [Manage many events easily with EventHandlerList](https://osherove.com/blog/2004/12/31/manage-many-events-easily-with-eventhandlerlist.html)

- Dec 30, 2004

    ### [Next generation iteration: Array.ForEach and Delegate inference](https://osherove.com/blog/2004/12/30/next-generation-iteration-arrayforeach-and-delegate-inferenc.html)

- Dec 29, 2004

    ### [Denying your public classes from your end customers](https://osherove.com/blog/2004/12/29/denying-your-public-classes-from-your-end-customers.html)

- Dec 29, 2004

    ### [Developing as non-admin made easier with VS.Net 2005?](https://osherove.com/blog/2004/12/29/developing-as-non-admin-made-easier-with-vsnet-2005.html)


---

## About the author

**Roy Osherove**: Senior Solutions Architect at AWS working on AI for production and AI-driven development; author of The Art of Unit Testing and Elastic Leadership, with about 20 years of consulting and training on unit testing, TDD, team leadership and continuous delivery.

### Sites

- [RobotPaper](https://robotpaper.ai/): This blog: AI patterns and anti-patterns, AI and coding agents, and engineering leadership.
- [osherove.com](https://osherove.com): Roy's personal site. Author of The Art of Unit Testing and Elastic Leadership; consulting and training on unit testing, TDD, team leadership and continuous delivery, plus about 20 years of blog posts.
- [The Art of Unit Testing](https://www.artofunittesting.com): The Art of Unit Testing, 3rd Edition (Manning): readable, maintainable, trustworthy unit tests, plus TDD workshops in C#, JavaScript, Java and Kotlin.
- [5whys.com](https://www.5whys.com): Roy's writing on software team leadership: self-organizing teams, surviving chaos, learning mode and the Elastic Leadership model.
- [Pipeline Driven](https://pipelinedriven.org): Continuous delivery and DevOps practices: build patterns, pipeline-friendly testing, DevOps metrics and enterprise DevOps.
- [Elastic Leadership](https://www.elasticleadership.com): Elastic Leadership, Roy's framework for software team leaders (survival, learning and self-organizing modes).

### Social

- X: https://x.com/royosherove
- LinkedIn: https://www.linkedin.com/in/osherove/

### Contact

- Contact form: https://forms.gle/jQSx5KoXvrVA1JCK7

### License

Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page). License: https://creativecommons.org/licenses/by/4.0/
