SmartAssembly 7

Error reporting and DLLs

Using error reporting with DLLs and an executable

To use error reporting with DLLs when you have your own executable, enable error reporting on both the .exe and the .dll in the SmartAssembly user interface.

Using error reporting with DLLs where you do not have an executable 

You can use error reporting in a DLL without applying error reporting to an executable (for example, if your product is DLLs which your customers include in their assemblies).

To add error reporting to a DLL without an executable, you must slightly modify the DLL, using either of the following methods: 

Method 1: Using SmartAssembly.ReportException.dll

This method involves calling the SmartAssembly Report Exception DLL from inside your DLL.

This is the preferred method, but it requires the SmartAssembly SDK (available in SmartAssembly Professional only).

  1. Reference the dependency %ProgramFiles%\Red Gate\SmartAssembly 7\SDK\bin\SmartAssembly.ReportException.dll (this dependency will be removed when processed).

    For .NET Core applications, you should use .NET Standard version of the SDK assembly, located in: %ProgramFiles%\Red Gate\SmartAssembly 7\SDK\bin\SmartAssembly.ReportException_NetStandard.dll

  2. For any public method of your DLL that can throw an exception which you wish to report, add a call to ExceptionReporting.Report as follows:

    using SmartAssembly.ReportException;
    public class MyClass
    {
       private void DoSomethingInternal()
       {
          //Your code here
       }
    
       public bool DoSomething()
       {
          try
          {
             DoSomethingInternal();
             return true;
          }
          catch (Exception exception)
          {
             ExceptionReporting.Report(exception);
             return false;
          }
       }
    }

Method 2: Creating a DLL with an entry point

This alternative method requires your DLL to have a specific entry point (most commonly add-ins and some web services). It involves changing your DLL so that it behaves similarly to an executable. This allows SmartAssembly to receive the exception as it will be passed to the Main() method.

This method might not work in all cases, since it will depend on the design of your application.

  1. Create a Console application executable file instead of a DLL. The only difference between the two is that the Console application has an entry-point.
  2. Do not type any code in the Main() method, SmartAssembly will add its own code in this here.
  3. In the static constructor of your plug-in class, call the Main()method.

    class Program
    {
       static void Main()
       {
          //empty
       }
    }
    
    class MyPlugin : IPlugin
    {
       static MyPlugin()
       {
          //ensure that sa initialization is executed
          Program.Main();
       }
    
       //your code here...
    }
  4. When you have finished writing the DLL code, rename the file from [filename].exe to [filename].dll.
  5. Use SmartAssembly to merge the DLL into your assembly.

Didn't find what you were looking for?