User-defined exceptions should be serializable.
Otherwise it will be not possible for exception to cross app domains.
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
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.
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:
@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?
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: