SmartAssembly - 5.5

SmartAssembly

Learning SmartAssembly - 5.5

Error reporting and DLLs

Reporting exceptions in DLLs

DLLs are intended to be used by an external application and so the DLL throws an exception which is then handled by the executable file which called the DLL. Therefore, SmartAssembly cannot report unhandled exceptions in a DLL; the executable which called the DLL receives the exception instead.

It may be possible to create a work around by slightly modifying the DLL.

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 5/SDK/bin/SmartAssembly.ReportException.dll (this dependency will be removed when processed).
  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 App executable file instead of a DLL. The only difference between the two is that the Console App 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.

Was this article helpful?

Search support
Forums
Visit the SmartAssembly forum.

SmartAssembly

all products