How can we help you today? How can we help you today?
Paul.Martin

Activity overview

Latest activity by Paul.Martin

The problem with DLL is that they are intended to be used by an external application. In this schema, throwing exceptions in a must-have. For example, this is the responsibility of the DLL to throw an ArgumentException if a method is not properly called. And the caller (the .EXE) must handle the exception and behave accordingly. So, most of the exceptions must be simply report to the caller. For this very reason, it is not possible to report unhandled exception as a global practice. That's why the option is not available for DLL in {smartassembly}. Anyway, a couple of workaround is available for some kind of DLL (mainly web-services or add-ins) but it requires a few changes in the DLL code (and {smartassembly}'s SDK for the second one): 1) Creating a DLL with an entry point. The trick is to create a Console App EXE instead of a DLL. The only difference between the two is that the Console App has an entry-point. You do nothing in the entry-point (the 'Main' method), but {smartassembly} will add its own code in this method. In the static constructor of your plug-in class, you call the entry-point. class Program { static void Main() { //empty } } class MyPlugin : IPlugin { static MyPlugin() { //ensure that {sa} initialization is executed Program.Main(); } //your code here... } Then, you just have to rename the .EXE into a .DLL, and you have a DLL with an entry-point. 2) Using SmartAssembly.ReportException.dll (Requires the Enterprise edition of {smartassembly}). You need to refer the dependency "C:\Program Files\{smartassembly}\SDK\bin\SmartAssembly.ReportException.dll" (this dependency will be removed when processed by {smartassembly}). Then, for any public method of your DLL that you want to protect, you need to do the following: Of course, you just need to do it for the "entry-points" of your DLL. 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; } } } A couple of things to note: - if you use method 1, SmartAssembly has slightly different default obfuscation and pruning settings for applications and libraries (for applications the protection is generally slightly stronger). - if you use method 2, on SmartAssembly 4 you need to manually add option to enable the unhandled exception feature in the project file. If you open the "{sa}proj" file for the library (it is a simple XML file) you need to add the node "<ExceptionReporting ReportExceptions="1" />" under the "Options" section - e.g. <SmartAssemblyProject> <Configuration> ......... <Options> ........... <ExceptionReporting ReportExceptions="1" /> </Options> </Configuration> </SmartAssemblyProject> In SmartAssembly 5 there is an option in the UI to change the setting so you don't have to manually edit the project file. The other method you can use is similar to method 2; however, instead of adding a try/catch to every method, you manually add a handler to the framework's unhandled exception event. The handled exception event varies being different types of applications. For a WPF class library the main one of AppDomain.UnhandledException. So you will want to add something like: Public Sub AppDom_UnhandledExceptions(ByVal sender As Object, ByVal args As UnhandledExceptionEventArgs) Handles _curDomain.UnhandledException SmartAssembly.ReportException.ExceptionReporting.Report(CType(args.ExceptionObject, Exception)) End Sub You will then need to add a static initialiser which links this event handler to the event. / comments
The problem with DLL is that they are intended to be used by an external application. In this schema, throwing exceptions in a must-have. For example, this is the responsibility of the DLL to throw...
0 votes
Ah, I've done a bit of digging and that is a bug. WPF has an extra unhandled exception event in the framework to WinForms. The events common between WPF and WinForms will work on WPF, however, in WPF they are both raised at a point where the application can't continue (it is possible to continue when the extra event in WPF is raised). I've logged a bug in our tracking system (SA-376) for our developers to fix. The only workarounds I can suggest in the meantime is either use the "ReportExceptionAttribute" on every method (which I know would be a real pain), or if you buy the Pro version you just need to add a handler for the missing event: Somewhere near the start of your application add a line: System.Windows.Threading.Dispatcher.CurrentDispatcher.UnhandledException += new System.Windows.Threading.DispatcherUnhandledExceptionEventHandler&#40;App_DispatcherUnhandledException&#41;; and then add the method to handle the event void App_DispatcherUnhandledException&#40;object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e&#41; &#123; e.Handled = true; SmartAssembly.ReportException.ExceptionReporting.Report&#40;e.Exception&#41;; &#125; (note you do need the Pro edition as the SDK, which ReportException.ExceptionReporting is part of, requires the Pro edition or Team package) / comments
Ah, I've done a bit of digging and that is a bug. WPF has an extra unhandled exception event in the framework to WinForms. The events common between WPF and WinForms will work on WPF, however, in W...
0 votes
There is a different program to run when you want to use the command line version. It is in the same folder as SmartAssembly.exe, but called SmartAssembly.com (or {smartassembly}.com for version 4 and earlier). / comments
There is a different program to run when you want to use the command line version. It is in the same folder as SmartAssembly.exe, but called SmartAssembly.com (or {smartassembly}.com for version 4 ...
0 votes