SmartAssembly 8

Error reporting with the SDK

The information on this page applies to SmartAssembly Pro only.

Using the SDK code samples

You can use the SDK to:

  • create a custom error reporting template (see below).
  • send custom emails when you receive error reports (see below).
  • attach custom files (for example, log files) to error reports (see Attaching files to error reports).
  • use SQL to fetch reports from the web service (see below).
  • use a transport protocol other than HTTP(S) for the error report, or to save an encrypted report to disk. 

Creating a custom error reporting template

To create a custom error reporting template, adapt the sample C# code from, then build the assembly as a DLL.

After you have built the DLL, change your error reporting settings in SmartAssembly to use your DLL instead of the default error reporting template.

  1. In the project settings window, either scroll to the Automated Error Reporting feature settings pane or, on the toolbar, click the automated error reporting icon.
  2. Select I want errors reported in my application.
  3. Select Custom Template.
  4. Click Browse for a Template and then select the DLL that you created.
  5. Enter the other information required for the Automated Error Reporting settings.
  6. Click Build.

When an exception is thrown, your application uses your DLL when it reports the error.

Sending custom emails when you receive error reports

If you choose to allow your customers to supply an email address with an error report, you can also set up an email response template. When you view your customer's error report, you can open the prepared response in your email client, ready to send to your customer.

File Extension

The error report requires a .saencryptedreport extension.

To set an email template, you first create a custom error report template:

  1. Ensure that your custom template adds the email field to the exception report as a custom property, by calling

    reportExceptionEventArgs.AddCustomProperty("Email", email.Text);
  2. Open the %PROGRAMDATA%\Red Gate\SmartAssembly 8\SmartAssembly.settings file in an XML editor.

  3. Inside the <Options> node, add an <ExceptionReports> node and set the EmailSubject and EmailBody attributes, as in this example:

     EmailSubject="Your SampleApp error report" 
     EmailBody="Hi,%0aI'm the developer of SampleApp.  Thanks for submitting an error report for my application recently.%0aIt looks as though you found a bug, and a patch fix is now available from again for helping to improve SampleApp!"
  4. Save the SmartAssembly.settings file.
  5. When you build your assembly, SmartAssembly merges the custom template with your own assembly.

    (Custom templates are merged even if Merge Dependencies is not enabled for the whole project.)

You can't set or read variables in the template email. We recommend you use placeholder text for product names and other information that might change. You can then replace this placeholder text in your email client, before sending the email.

Using SQL to fetch reports from the web service with SmartAssembly SDK

You can write your own SQL query to fetch error reports from the webservice. Writing your own query allows you to integrate error reporting with your existing bug reporting systems, and can be used to email the right developer about certain types of report, for example.

We recommend that you start by adapting the sample application provided.

The sample application is a C# project included at project includes a reference to a RedGate.SmartAssembly.SDK package, but this obfuscated DLL only sends the SQL queries to the web service. The SQL queries themselves are constructed in the unobfuscated *.cs files in \Data\.

More information about the SDK samples

The supplied code samples are derived from SmartAssembly.SmartExceptionsCore.UnhandledExceptionHandler and are based on the following four methods, which your assembly should also implement:

  • OnSecurityException(SecurityExceptionEventArgs)
    Called when a System.Security.SecurityException is thrown.
  • OnReportException(ReportExceptionEventArgs)
    Called when any other type of exception is thrown. The ReportExceptionEventArgs object supplied to this method encapsulates the report which is to be sent. You can therefore add files and extra parameters to this object or save and send the report within this method.
  • OnFatalException(FatalExceptionEventArgs)
    Called if the Unhandled Exception handler fails for any reason.
  • AttachApp()
    Used to attach your customised error reporting form to the application.
    A call to this method is added automatically by SmartAssembly when you build an assembly with error reporting. In most cases, you do not need to edit this method.

Didn't find what you were looking for?