简体   繁体   English

IServiceCollection不包含AddHttpClient的定义

[英]IServiceCollection does not contain a defintion for AddHttpClient

I am trying to use HttpClient in my .net core 2.0 project and for that I have injected HttpClient in my controller. 我试图在我的.net核心2.0项目中使用HttpClient,为此我已经在我的控制器中注入了HttpClient。 But when I am trying to configure httpclient in my startup.cs I am getting this error: "IServiceCollection does not contain a defintion for AddHttpClient". 但是,当我尝试在我的startup.cs中配置httpclient时,我收到此错误:“IServiceCollection不包含AddHttpClient的定义”。 I have already referenced using Microsoft.AspNetCore.Http; 我已经using Microsoft.AspNetCore.Http;引用了using Microsoft.AspNetCore.Http; and using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection; and here is what I am trying to do: 这就是我要做的事情:

services.AddHttpClient<TestController>();

It's working fine in other project with same namespaces but here I am getting the error. 它在具有相同命名空间的其他项目中工作正常,但在这里我得到了错误。 Any help? 有帮助吗?

您需要从NuGet安装Microsoft.Extensions.Http。

Aah, I have found the solution. 啊,我找到了解决方案。 I think services.AddHttpClient work with .net core 2.1. 我认为services.AddHttpClient与.net核心2.1一起工作。 So I updated my .net core version to 2.1 and updated the microsoft packages to 2.1 and it starts working. 所以我将.net核心版本更新为2.1并将微软软件包更新为2.1并开始工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iServiceCollection' 不包含 'addVersionedApiExplorer' 的定义 - iServiceCollection' does not contain a definition for 'addVersionedApiExplorer' IserviceCollection 不包含“AddDefaultIdentity”的定义 - IserviceCollection does not contain defination of “AddDefaultIdentity” IServiceCollection不包含AddMvc()的定义 - IServiceCollection does not contain definition for AddMvc() “IServiceCollection”不包含“AddControllers”的定义 - 'IServiceCollection' does not contain a definition for 'AddControllers' “IServiceCollection”不包含“AddSpaStaticFiles”的定义 - 'IServiceCollection' does not contain a definition for 'AddSpaStaticFiles' IServiceCollection 不包含 AddQuartz 的定义 - IServiceCollection does not contain definition for AddQuartz “IServiceCollection”不包含“AddPolicyHandler”的定义 - 'IServiceCollection' does not contain a definition for 'AddPolicyHandler' “IServiceCollection”不包含“AddIdentity”的定义 - 'IServiceCollection' does not contain a definition for 'AddIdentity' IServiceCollection 不包含定义 AddJsEngineSwitcher - IServiceCollection Does not contain definition AddJsEngineSwitcher IGrouping <decimal,string> 不包含“名称”的定义 - IGrouping <decimal,string> does not contain a defintion for 'name'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM