C #, Metro app, custom exception class

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?

+6
source share
1 answer

It does not seem that System.Runtime.Serialization.SerializationInfo supported in the Metro-compatible version of the .NET framework. See http://msdn.microsoft.com/en-us/library/windows/apps/hh454059(v=vs.110).aspx for information on which classes they prefer to support from the System.Runtime namespace. Keep in mind that this is subject to change.

So yes, pull out your Serialization attribute and private constructor.

+2
source

Source: https://habr.com/ru/post/913950/


All Articles