Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementing custom exceptions in a Portable Class Library

When designing custom exceptions for .NET, MSDN provides these guidelines. In particular, the guidelines state that a custom exception:

  • should be serializable, i.e. implement ISerializable and be decorated with the [Serializable] attribute, and
  • should implement the (de)serialization constructor, i.e. protected CustomException(SerializationInfo info, StreamingContext context).

However, in a Portable Class Library neither of SerializableAttribute, ISerializable and SerializationInfo are supported.

How should I sufficiently design a custom exception in a Portable Class Library that simultaneously targets .NET Framework and one or more platforms?

like image 512
Anders Gustafsson Avatar asked Nov 28 '12 12:11

Anders Gustafsson


1 Answers

Basically, ignore that guidance - that is for full .NET, and does not apply to portable class library projects. Indeed, if we look at (say) Silverlight (which includes WP7) we see:

[ClassInterfaceAttribute(ClassInterfaceType.None)]
[ComVisibleAttribute(true)]
public class Exception

Frankly, the main consumer of that requirement was remoting... and that is not in huge demand now.

like image 121
Marc Gravell Avatar answered Sep 18 '22 20:09

Marc Gravell