我正在创建一个自定义配置部分,它允许我管理我想从我的 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 问题。我在这里做错了什么?