SmartAssembly SDK

From RedGateWiki
Jump to: navigation, search

Contents

Sample Code

Custom Error Reporting Overview

In order to use custom error reporting, you must first create a class library (DLL) referencing SmartExceptionsCore.dll. This DLL will determine how unhandled exception reporting is done in the application that you protect using SmartAssembly. Your class should inherit from UnhandledExceptionHandler and can override event handlers used by SmartAssembly, for instance:

  • OnSecurityException
  • OnReportException
  • OnFatalException

...and should also contain a method called AttachApp() that calls AttachExceptionHandler.

The second part is to set SmartAssembly to use the DLL that you had created. SaCustomError.png


Please note that error reporting adds code to the assembly to catch local variables and implement an UnhandledExceptionHandler. Therefore, it needs to modify an executable. If you want to add error reporting to a DLL (for instance an Office add-in), you may use the ReportException method described in the product help.

Code Samples

Sample API version Language
Error reporting - no UI 4,5&6 C#  VB
Adding a custom property to an exception 4,5&6 C#  VB
Getting an exception report from the database 4,5&6 C#  VB
Make a build expire 5&6 C#  VB
Check the version of SA used to build an assembly 5&6 C#  VB

References

Class reference document for SmartAssembly 5.5 SDK in Compressed HTML format

Class reference document for SmartAssembly 6.0 SDK in Compressed HTML format

Class Reference document for SmartAssembly 6.5 SDK in Compressed HTML format

Custom Web Server

You can set up your own SmartAssembly reporting server. There are different instructions for SmartAssembly v4 ( Media:HowToSetupCustomWebServer.zip ) and SmartAssembly v5.

Blogs

Describes basically how the obfuscation works and why you would want to use it

Tips

  • Obfuscation will not hide property names on classes - this is done using pruning
  • Obfuscation and pruning effects on serializable classes to be aware of
  • Obfuscation and pruning effects on Reflection and late-binding to be aware of
  • Silverlight event delegate methods need to be excluded manually from obfuscation (not always... don't know when)
  • LINQ (to SQL) - Do not prune or obfuscate any member using the System.Data.Linq.Mapping.Table attribute.
    • Anonymous types used in LINQ and Lambda need to be excluded from obfuscation manually
  • Assembly merging can break equivilence and/or type conversion at runtime. Try embedding instead.

Obfuscation exclusions

  • Any type with the Serializable attribute specified will not be obfuscated
  • Any type with a base class of System.MulticastDelegate will not be obfuscated
  • Any type with the System.ServiceModel.OperationContractAttribute specified will not be obfuscated
  • Any type with the System.ServiceModel.ServiceContractAttribute specified will not be obfuscated
  • Any method with the System.Reflection.DefaultMemberAttribute specified will not be obfuscated
  • Any type with an attribute starting with System.Xml.Serialization. set will not be obfuscated
  • Any type with the DataContract, ServiceContract, or MessageContract attributes set (WCF, since v6.5)

(note: this list may not be complete at this time)

Merging /embedding exclusions

  • Mixed managed/unmanaged code
  • Primary Interop Assemblies
  • In v6.2 and lower, Anything at all signed using Microsoft's strong-naming key (PublicKeyToken=31bf3856ad364e35)
- A possible workaround would be to use ILDASM.exe from the .NET SDK and dump the IL to a folder and then use ILASM to link it back together using your own strong-name key. This seems to work on assemblies that are not part of the Framework proper.

Misc

  • If you want to manually send an exception to SmartAssembly's UnhandledExceptionHandler, you may use the method:

SmartAssembly.ReportException.ExceptionReporting.Report(System.Exception exception)

Note that the local variables and the stack trace are missing for the method which called Report. A workaround is to wrap the whole method up in a delegate. Example

  • To add a custom property to an exception report, use the AddCustomProperty method on the ReportExceptionEventArgs object.

This creates a name/value pair for any custom information that you want to add to the exception report.

  • If you need to check whether an assembly you have built was built with a licensed copy of SmartAssembly, look for the DoNotDistribute attribute at the assembly level. If this is present, the build will expire in 20 days.
Personal tools