电话是单一的方法即扩展方法之间的暧昧 [英] The call is ambiguous between single method i.e extension method

查看:167
本文介绍了电话是单一的方法即扩展方法之间的暧昧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像

public static class Extension
{
    public static string GetTLD(this string str)
    {
        var host = new System.Uri(str).Host;
        int index = host.LastIndexOf('.'), last = 3;
        while (index >= last - 3)
        {
            last = index;
            index = host.LastIndexOf('.', last - 1);
        }
        var domain = host.Substring(index + 1);
        return domain;
    }
}

我象

string domain = "." + _url.GetTLD();

我正在逐渐建立和干净生成任何错误。结果
但我正在逐渐编译错误在运行时错误说

在调用以下方法或属性之间暧昧:
  myIGNOU.Extension.GetTLD(字符串)和
  myIGNOU.Extension.GetTLD(字符串)

The call is ambiguous between the following methods or properties: 'myIGNOU.Extension.GetTLD(string)' and 'myIGNOU.Extension.GetTLD(string)'

我发誓,我没有这个扩展方法放置在任何别的地方过该项目。
为什么我只在运行时收到此错误..?

I swear that I don't have this extension method placed any where else too in the project. Why I am getting this error only at run time..?

但是,如果我删除此方法,那么我在制作的时候不是在运行时不收到错误。一切正常没有这个方法的code。

But if I delete this method then I am getting error at build time not not at run time. Everything works fine without the code of this method.

以下是编译错误页面

推荐答案

这是不是一个真正的解决方案,我无法解释它是如何工作,但它的工作。

This is not a real solution and I can't explain how did it work but it worked.

我在项目属性,引用,仓乱投医,OBJ但没有任何帮助我来说真的。而我只是想每一个选项,并选择转换为Web应用程序从上下文菜单。虽然这是一个Web应用程序本身之前。这表明我一个警告说,了.Designer.cs 文件将被添加到每个aspx文件,我只是点击确定。

I was trying everything in Project Properties, References, bin, obj but nothing helped me really. And I was just trying every option and chose 'Convert to Web Application' from the context menu. Although It was a Web Application itself before. It showed me a warning saying that .designer.cs files will be added to each aspx file and I just clicked OK.

一切仍然只是 APP_ code 同一文件夹中(所有这些类人)被重命名为老APP_ code ,我会构建项目。现在我不是在运行时获得编译错误。

Everything remained same except App_Code folder (where all these classes were) was renamed to Old App_Code and I'd build the project. And now I am not getting compilation error at run time.

我知道APP_ code文件夹是为了网站项目,我是有这个没什么事,直到这次在WAP。但我只是知道我不应该APP_ code文件夹中的WAP,因为它是在<一个在这里讨论href=\"http://p2p.wrox.com/book-beginning-asp-net-3-5-c-vb-book-isbn-978-0-470-18759-3/73539-app_$c$c-folder-web-application-project.html#post237879\">wrox论坛(第1点)。笔者在这里说,

I know App_Code folder are meant to Website Project and I was having no issue with this till this time in WAP. But I just realize I should not have App_Code folder in WAP as it is discussed here in a wrox forum (1st point). Author has said here that

APP_ code未在一个WAP支持。该APP_ code文件夹是在编译
  运行时的;在WAP的所有code编译/开发时间进行编译。所以,当你添加一个APP_ code文件夹复制到WAP。你结束了
  复制code;例如,在APP_ code中定义的类也将
  在WAP DLL露面。解决方法是简单:只需将文件夹命名
  别的像类或codeFiles。

App_Code is not supported in a WAP. The App_Code folder is compiled at run-time; all code in a WAP is compiled at compile / development time. So, when you add an App_Code folder to a WAP. you end up with duplicate code; for example, a class defined in App_Code will also show up in the wap DLL. The fix is easy: just name the folder something else like Classes or CodeFiles.

我已经尝试过太更名转换前,但当时没有工作。

I have tried it renaming too before conversion but that time it did not work.

这篇关于电话是单一的方法即扩展方法之间的暧昧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆