我正在尝试使用 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/