JamesFaix
JamesFaix

Reputation: 8665

Using `StackExchange.Precompilation`, how can I output build errors?

I am using StackExchange.Precompilation to perform some C# syntax transformations on build. I would like to be able to throw exceptions from my ICompileModule during the build and have those output to Visual Studio's output window.

I have created a custom exception type PrecompilationException to represent errors that occur during these syntax transformations. Here is my exception class:

[Serializable]
public class PrecompilationException : Exception {

    public PrecompilationException() : base() { }

    public PrecompilationException(string message) : base(message) { }

    public PrecompilationException(string message, Exception innerException) : base(message, innerException) { }

    protected PrecompilationException(SerializationInfo info, StreamingContext context) : base(info, context) { }
}

When one of these exceptions is thrown, the output window shows a SerializationException whose message is "Type is not resolved for member 'PrecompilationException...", but there are no details of that PrecompilationException like its message or stack trace.

Did I leave out something important for proper serialization in my exception class? Is there a better way to get StackExchange.Precompilation to log errors?


Update If I change the exception type being throw to something standard like Exception or NotSupportedException the output window will show the exception details. However, I would still like to be able to use custom exception types in this way.

Update2 The answer to this question sheds some light on why my custom exception type was not working. Basically, the ASP.NET compiler has trouble serializing types that aren't in the GAC.

Type resolution error during ASP.NET precompilation

Upvotes: 2

Views: 254

Answers (1)

m0sa
m0sa

Reputation: 10940

Just add a Diagnostic to the Diagnostics collections in Before/AfterCompileContext.

The other alternative is to Console.WriteLine in the MsBuild VS-Aware error message format

Upvotes: 2

Related Questions