For many years, I followed MS’s recommendations for writing a custom exception class (I don’t even remember if it was first used by FxCop or an article I read), and wrote my classes as follows:
using System; using System.Runtime.Serialization; [Serializable] public sealed class MyGreatException : Exception { public MyGreatException() : base() {} public MyGreatException(string message) : base(message) {} public MyGreatException(string message, Exception inner) : base(message, inner) {} private MyGreatException(SerializationInfo info, StreamingContext context) : base(info, context) {} }
Today, these classes are rejected by the Windows 8 App Cert Kit:
.API System.Runtime.Serialization.SerializationInfo in MSCORLIB, PUBLICKEYTOKEN=B77A5C561934E089 is not supported for this application type. com.visionobjects.myscript.hwr.dll calls this API. .API System.SerializableAttribute in MSCORLIB, PUBLICKEYTOKEN=B77A5C561934E089 is not supported for this application type. com.visionobjects.myscript.hwr.dll calls this API.
(among other deviations ...)
So now that in 2012, how do I write my own exception class? I just need to remove [Serializable]
, and should the private constructor deal with custom serialization (which I don't need anyway)?
EDIT
I removed [Serializable]
and the private constructor. I assume that my own exception class is not serializable. How is a class opened by a class library, how does it affect code using a library?
source share