I'm using SmartAssembly for both general code obfuscation as well as error reporting in an application.
If my application encounters an unhandled exception, I'd like the exception to be logged and then terminate the application without any user interaction. Is it possible to create a SmartAssembly project that allows this?
I've tried setting up the project in the SmartAssembly GUI, as well as on the command-line with no luck. Below is the command and arguments I've tried, but so far I can't determine how to get it to both terminate the app and log the error with no user input.
Create SA Project:
"C:\Program Files\Red Gate\SmartAssembly 6\SmartAssembly.com"
/create shell.saproj input=C:\Repositories\MyApp\src\shell.exe
/output=shell.exe
/reportappname="MyTestApp"
/errorreportingtemplate=standard;continueonerror=false,email:"my@email.com"
/reportprojectname="Shell"
/reportcompanyname="My Company"
Build the project:
"C:\Program Files\Red Gate\SmartAssembly 6\SmartAssembly.com" /build shell.saproj
SmartAssembly includes a few examples of custom ErrorReportingTemplates,
located in Red Gate/SmartAssembly 6/SDK/Exception Reporting/
The examples are lumped into a few categories:
Without UI
Standard
Custom UI
Via Email
Secured Proxy
Silverlight
Silverlight Basic
In each of these folders, there is a .csproj file that one can extend to get their desired results.
Inside the Without UI
folder is the project we're after, titled Sample 01 - Without User Interface.csproj
If you're just after a .dll
to use and don't care about a re-usable solution, edit this file directly and use the resulting .dll
file (the alternative being to create a new project, and pull in the reference to SmartAssembly.SmartExceptionsCore
).
Edit the OnReportException
function to look like the following:
protected override void OnReportException(ReportExceptionEventArgs e)
{
for (int i=0; i<3; i++)
{
if (e.SendReport()) break;
}
e.TryToContinue = false;
System.Diagnostics.Process proc = System.Diagnostics.Process.GetCurrentProcess();
proc.Kill();
}
Here's a Gist of the final result, if you're confused.
Create the project file with the GUI or via cmd:
"C:\Program Files\Red Gate\SmartAssembly 6\SmartAssembly.com"
/create shell.saproj input=C:\Repositories\MyApp\src\shell.exe
/output=shell.exe
/reportappname="MyTestApp"
/errorreportingtemplate=MySmartAssemblyLogger.dll;continueonerror=false,email:"my@email.com"
/reportprojectname="Shell"
/reportcompanyname="My Company"
Build with the GUI or via cmd:
"C:\Program Files\Red Gate\SmartAssembly 6\SmartAssembly.com" /build shell.saproj