Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C#, Metro Application, custom exception class

For years, I've been following MS best practices on how to write a custom exception class (don't even remember if it was first enforced by FxCop or by an article I read) and wrote my classes the following way:

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 get rejected by 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 rejects...)

So now that it's 2012, how do I write a custom exception class? Do I just have to remove [Serializable] and the private constructor supposed to deal with custom serialization (which I don't need anyway)?


EDIT

I removed [Serializable] and the private constructor. I guess that makes my custom exception class non serializable. As this is a class exposed by a class library, how does that impact the code using the library?

like image 469
Gregory Pakosz Avatar asked Apr 23 '12 15:04

Gregory Pakosz


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

Is C language easy?

Compared to other languages—like Java, PHP, or C#—C is a relatively simple language to learn for anyone just starting to learn computer programming because of its limited number of keywords.

What is C in C language?

What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.


1 Answers

It doesn't look like System.Runtime.Serialization.SerializationInfo is supported yet 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 details about which classes they're choosing to support from the System.Runtime namespace. Keep in mind, this is subject to change.

So yes, take out your Serialization attribute and the private constructor.

like image 133
villecoder Avatar answered Oct 26 '22 20:10

villecoder