【问题标题】:Using ELMAH with ASP.NET MVC in VB: Compiling: Elmah does not have a strong name在 VB 中将 ELMAH 与 ASP.NET MVC 一起使用:编译:Elmah 没有强名称
【发布时间】:2009-08-27 00:08:11
【问题描述】:

我已经阅读了将 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 收到以下错误:

错误 3 无法发出程序集:引用的程序集“Elmah”没有强名称 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\我的文档\burrow\code\代码签名key.pfx" Microsoft (R) .NET Framework 强名称实用程序版本 3.5.30729.1 版权所有 (c) 微软公司。版权所有。 C:\Documents and Settings\zchoy\My Documents\Burrow\Code\Main\lib\Elmah.dll 确实 不代表强命名程序集

显然没有帮助。

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

    • 如果你有源代码就好了。一般来说,al.exe 是解决方案。
    • 您能否详细说明使用 al.exe 对未标记为延迟签名的已编译程序集(不是模块)进行签名的确切语法?我无法让它工作,而且我在 al.exe 的文档中看不到任何让我认为它应该工作的东西。过去,我不得不求助于 ILDASM/ILASM 来获取我没有源代码的程序集的签名版本,如果 al.exe 能解决这个问题,它会简单得多。
    • @Joel:根据devnewsgroups.net/group/microsoft.public.dotnet.framework/…,更准确的说法是 al.exe 允许您创建一个已签名的新程序集,而不是对现有程序集进行签名。
    • 我同意,史蒂文。您链接到的那个线程还说,“您不能使用 Al.exe 签署现有的未签名程序集。”你好像说反了,这样会很方便,所以我才要举个例子。
    【解决方案2】:

    看来您需要对 Elmah 程序集进行签名,以使其具有强名称。

    【讨论】:

    • 没有帮助,当我尝试签名时,sn.exe 将其吐出:>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 强名称实用程序版本 3.5.30729.1 版权所有 (c) Microsoft Corporation。版权所有。 C:\Documents and Settings\zchoy\My Documents\Burrow\Code\Main\lib\Elmah.dll 不代表强命名程序集
    • 我认为您需要使用 al 而不是 sn 来签署它,尽管您需要先使用 sn 生成密钥。有关说明,请查看msdn.microsoft.com/en-us/library/xc31ft41.aspx
    • 这些说明讨论了如何从一个或多个模块中创建签名程序集,以及如何使用在编译时标记为延迟签名的程序集,但似乎什么也没说关于如何签署一个已经存在但编译时没有强名称的程序集。
    猜你喜欢
    • 2011-04-30
    • 1970-01-01
    • 2010-09-24
    • 2010-12-17
    • 2010-10-20
    • 2017-10-02
    • 2011-09-23
    • 2011-03-20
    • 2011-01-08
    相关资源
    最近更新 更多