Docs: Serializable

Created on 14 Jun 2018  Â·  7Comments  Â·  Source: dotnet/docs

User-defined exceptions should be serializable.
Otherwise it will be not possible for exception to cross app domains.


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Area - .NET Guide Area - C# Guide Technology - C# Fundamentals P2 Pri2 doc-enhancement dotneprod

Most helpful comment

Issues to address in revising the custom exceptions article

The article is intended to be a "how to" that shows how to create a custom exception. It fails conspicuously. It needs to be revised as follows:

  1. It should implement some type of practical custom exception type.
  2. It should explicitly mention that exceptions inherit from Exception.
  3. It should implement at least one custom member other than a constructor.
  4. It should make the exception object serializable.

All 7 comments

I apologize for the belated response, @nex-54. This article should discuss serialization of custom exceptions, but conspicuously fails to do so. We'll address that and other issues, which I'll list in my subsequent comment, in our next sprint, which begins on Monday, July 23.

Issues to address in revising the custom exceptions article

The article is intended to be a "how to" that shows how to create a custom exception. It fails conspicuously. It needs to be revised as follows:

  1. It should implement some type of practical custom exception type.
  2. It should explicitly mention that exceptions inherit from Exception.
  3. It should implement at least one custom member other than a constructor.
  4. It should make the exception object serializable.

@rpetrusha

It should make the exception object serializable.

Should that actually be the recommended practice in new code? Considering that this is only necessary if you use technologies like BinaryFormatter or AppDomain, which are generally considered not recommended anymore, especially if you're targeting .Net Core.

Any update on this will it make it into this sprint? I am looking to make my own custom exception and love to be able to use this.

Y'all crack me up. Not everything needs to be serializable. That comes down to YOUR specific requirements for YOUR specific project. This article is meant to be a base, it's not meant to write your code for you or cover every possible requirement that might exist.

Some of this information can be found at the following link; possibly they should be consolidated into a single page or section of a page: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/exceptions/creating-and-throwing-exceptions#defining-exception-classes

I also agree with @svick - should either of these guides be blindly recommending the [Serializable] attribute? Or should they be more nuanced as to when it's appropriate/necessary to apply that attribute?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stanuku picture stanuku  Â·  3Comments

garfbradaz picture garfbradaz  Â·  3Comments

ike86 picture ike86  Â·  3Comments

JagathPrasad picture JagathPrasad  Â·  3Comments

ygoe picture ygoe  Â·  3Comments