下面是我的扩展方法:
Public Module HtmlExtensions System.Runtime.CompilerServices.Extension Public Function ReverseMapPath(ByVal html As HtmlHelper, ByVal path As String) As String Dim appPath = HttpContext.Current.Server.MapPath("~") Dim res As String = String.Format("{0}", path.Replace(appPath, "/").Replace("\", "/")) Return res End Function End Module My web.config为我的命名空间提供了一个条目
一切都运行得很好。我开始向项目中添加更多的代码,现在我得到一个错误,看起来好像我加载了两次扩展方法,但我不知道为什么。错误是:path.page.vbhtml(9): error BC30521: Overload resolution failed because no accessible 'FunctionName' is most specific for these arguments: Extension method 'Public Function FunctionName(path As String) As String' defined in 'namespace.Extensions.HtmlExtensions': Not most specific. Extension method 'Public Function FunctionName((path As String) As String' defined in 'namespace.Extensions.HtmlExtensions': Not most specific.
我不明白为什么这件事会悄悄发生。很明显,我改变了一些东西,但是撤销所有的东西并没有帮助。错误似乎更多地隐藏在.net框架后面。有什么想法吗?
发布于 2014-08-20 02:59:56
我刚刚遇到了这个问题。如果你阅读了CrazyTim评论的链接,问题来自于VS在项目中添加对自身的引用。
如果你遇到这个问题,VS可能已经在你的项目中添加了对自身的引用。删除引用,你就会正确无误。
发布于 2012-08-18 10:22:02
这似乎是一个名称空间问题。我的扩展类的名称空间是Global.ProjectName。一旦我改变了这一点,一切都会正常工作。由于命名空间的原因,它必须加载它两次。
https://stackoverflow.com/questions/12015048
复制相似问题