ASP.NET WebApi - HttpClient - 找不到方法

标签 asp.net httpclient asp.net-web-api

我正在尝试使用 Asp.NET WebAPI 模块,但收到一个奇怪的错误。 当我尝试运行这个简单的程序时:

class Program
{
    static void Main(string[] args)
    {
        System.Net.Http.HttpClient client = new HttpClient();
        string data = client.GetStringAsync("http://www.kralizek.se/").Result;

        Console.WriteLine(data);

        Console.ReadLine();
    }
}

我有这个错误。

System.MissingMethodException was unhandled
  Message=Method not found: 'System.Threading.Tasks.Task`1<System.String> System.Net.Http.HttpClient.GetStringAsync(System.String)'.
  Source=Connector.App
  StackTrace:
       at ConnectorApp.Program.Main(String[] args)
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()

该错误发生在 Visual Studio 和 LinqPad 中,但我的同事没有发生。

我认为可能与 .NET 4.5 开发预览版存在某种冲突,因此我卸载了它,但没有任何好处。

谢谢

最佳答案

ASP.NET Web API Beta 明显与 .NET Framework 4.5 开发人员预览版不兼容。请参阅http://www.asp.net/whitepapers/mvc4-release-notes#_Toc303253802 .

我建议卸载两者并在清除两者后重新安装 Web API。我认为在安装 Web API 之后卸载 .NET 4.5 不会有效果。

关于ASP.NET WebApi - HttpClient - 找不到方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9787480/

相关文章:

c# - 版本控制 API 端点

.net - ASP.NET 2.0编译错误: Make sure that the class defined in this code file matches the 'inherits' attribute

c# - 如何使用特定的用户名和密码启动 IIS 进程

c# - 如何模拟/单元测试 HTTP 客户端 - restease

c# - 为什么在 owin 实现后,swagger 不起作用?

c# - 如何在 WebAPI 上实现 SOAP 服务

asp.net - 是否需要对密码输入进行清理?

css - scss 文件在本地工作但在部署中不起作用,在 chrome 中工作,在 IE 中不工作

java - 上传文件时如何从HttpEntity中删除请求 header

oauth - 获取 Zoho API 的授权