【发布时间】:2012-05-11 22:51:10
【问题描述】:
我正在创建一个自定义配置部分,它允许我管理我想从我的 VB.NET/ASP.NET 应用程序中忽略的 ELMAH 异常。这是我的代码。如果有人愿意接受诊断问题的挑战,我可以很容易地粘贴到空白代码文件中。
Imports System.Configuration
Namespace ElmahExceptionHandling
Public Class IgnoredExceptionSection : Inherits ConfigurationSection
<ConfigurationProperty("IgnoredExceptions")>
ReadOnly Property IgnoredExceptions As IgnoredExceptions
Get
Return TryCast(Me("IgnoredExceptions"), IgnoredExceptions)
End Get
End Property
Shared Function GetConfig() As IgnoredExceptionSection
Return TryCast(System.Configuration.ConfigurationManager.GetSection("IgnoredExceptionSection"), IgnoredExceptionSection)
End Function
End Class
<ConfigurationCollection(GetType(IgnoredException))>
Public Class IgnoredExceptions : Inherits ConfigurationElementCollection
Protected Overloads Overrides Function CreateNewElement() As System.Configuration.ConfigurationElement
Return New IgnoredException
End Function
Protected Overrides Function GetElementKey(element As System.Configuration.ConfigurationElement) As Object
Return TryCast(element, IgnoredException).Message
End Function
End Class
Public Class IgnoredException : Inherits ConfigurationElement
<ConfigurationProperty("Message")>
ReadOnly Property Message As String
Get
Return Me("Message")
End Get
End Property
End Class
End Namespace
这是配置:
<configSections>
<section name="IgnoredExceptionSection" type="ElmahExceptionHandling.IgnoredExceptionSection, WEB" />
</configSections>
<IgnoredExceptionSection>
<IgnoredExceptions>
<add Message="test exception" />
</IgnoredExceptions>
</IgnoredExceptionSection>
当我执行这段代码时:
Dim section As ElmahExceptionHandling.IgnoredExceptionSection = ConfigurationManager.GetSection("IgnoredExceptionSection")
我收到错误An error occurred creating the configuration section handler for IgnoredExceptionSection: Could not load file or assembly 'WEB' or one of its dependencies.。
令我惊讶的是,在我使用 Web 实用程序从 VB.NET 转换代码后,这一切都在我的 C# 控制台测试应用程序中运行良好。但是,当我将 Web 应用程序中的 VB 代码粘贴到我的 VB.NET 控制台测试应用程序中时,它在那里也不起作用,因此它似乎是一个 C#/VB 问题。我在这里做错了什么?
【问题讨论】:
-
您需要使用Fusion log viewer. 进行调试,只需确保以管理员身份运行它,打开日志,然后在尝试调试之前重新启动。您将看到 CLR 在哪里寻找程序集,以及什么版本,并从那里确定为什么找不到它(如果您甚至安装了它)。
-
我想这个问题被否决了,因为人们不喜欢以这种方式取消例外的想法。投反对票的人没有给出任何投反对票的理由(对于 Stack Exchange 来说,这是一种低效的方法)。
标签: vb.net .net-4.0 web-config app-config asp.net-4.0