在VB中使用ELMAH和ASP.NET MVC:编译:Elmah没有强名称

时间:2009-08-27 00:08:12

标签: asp.net-mvc vb.net elmah

我已经阅读了将ASP.NET MVC HandleError错误传递给ELMAH的帖子和代码,并将代码转换为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

然而,我注意到当我尝试编译代码时,我从VS2008收到以下错误:

Error  3   Unable to emit assembly: Referenced assembly 'Elmah' does not have a strong name    Main

现在,HandleErrorAttribute.vb位于[带有SLN文件的文件夹] \ Main \ HandleErrorAttribute.vb中,而视图,控制器等都位于Main文件夹下。

如果您能够使原始C#代码生效,您是如何解决编译时错误的? (并且,如果你让它在VB中工作,那就更好了)

修改

我已经尝试使用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

显然没有帮助。

2 个答案:

答案 0 :(得分:6)

当我遇到此问题时,我downloaded the ELMAH source code并在Visual Studio中将其打开。然后我使用项目属性上的Signing选项卡对程序集进行签名,然后编译我自己的Elmah.dll版本。

然后我将这个签名版本链接到我的主项目中。

答案 1 :(得分:0)

看起来您需要签署Elmah程序集,以便它具有强大的名称。