I've read through the posts and code for passing ASP.NET MVC HandleError errors to ELMAH and converted the code to VB:
Imports System
Imports System.Web
Imports System.Web.Mvc
Imports Elmah
Public Class HandleErrorAttribute
Inherits System.Web.Mvc.HandleErrorAttribute
Public Overrides Sub OnException(ByVal context As ExceptionContext)
MyBase.OnException(context)
Dim e As Exception = context.Exception
If Not context.ExceptionHandled OrElse RaiseErrorSignal(e) OrElse IsFiltered(context) Then
' if unhandled, will be logged anyhow
'prefer signaling, if possible
'filtered?
Else
LogException(e)
End If
End Sub
Private Function RaiseErrorSignal(ByVal e As Exception) As Boolean
Dim context = HttpContext.Current
If context Is Nothing Then Return False
Dim signal = ErrorSignal.FromContext(context)
If signal Is Nothing Then Return False
signal.Raise(e, context)
Return True
End Function
Private Function IsFiltered(ByVal context As ExceptionContext) As Boolean
Dim config As ErrorFilterConfiguration = context.HttpContext.GetSection("elmah/errorFilter")
If config Is Nothing Then Return False
Dim testContext = New ErrorFilterModule.AssertionHelperContext(context.Exception, HttpContext.Current)
Return config.Assertion.Test(testContext)
End Function
Private Sub LogException(ByVal e As Exception)
Dim context = HttpContext.Current
ErrorLog.GetDefault(context).Log(New Elmah.Error(e, context))
End Sub
End Class
However, I noticed that when I try to compile the code, I get the following error from VS2008:
Error 3 Unable to emit assembly: Referenced assembly 'Elmah' does not have a strong name MainRight now, HandleErrorAttribute.vb lives in [folder with the SLN file]\Main\HandleErrorAttribute.vb and the Views, Controllers, and so on are all under the Main folder. If you were able to get the original C# code to work, how did you get around the compile-time error? (and, if you got it to work in VB, that's even better) **Edit** I've already tried signing it with sn.exe:
C:\Program Files\Microsoft Visual Studio 9.0\VC>sn -R "C:\Documents and Settings \zchoy\My Documents\Burrow\Code\Main\lib\Elmah.dll" "C:\documents and settings\z choy\my documents\burrow\code\code signing key.pfx" Microsoft (R) .NET Framework Strong Name Utility Version 3.5.30729.1 Copyright (c) Microsoft Corporation. All rights reserved. C:\Documents and Settings\zchoy\My Documents\Burrow\Code\Main\lib\Elmah.dll does not represent a strongly named assembly
Clearly unhelpful.