1
votes

I try to send a get request to web api. but visual studio 2017 doesn't make sense to HttpClient obeject methods! it draw a red line under my instance and gives the error: Error CS7069 Reference to type 'Task<>' claims it is defined in 'System.Runtime', but it could not be found. note that this is different from other errors which is occurs in UWP and Xamarin with same message.

string Baseaddress = "https://localhost:44305/api/values";
HttpClient _client = new HttpClient();
var result = await _client.GetAsync(Baseaddress);
1
You just need to do var result = await _client.GetAsync(Baseaddress); Remove the .Resultrbm
@rbm the origin of problem is something other. I removed it but the problem remains.Hamed Sanaei

1 Answers

1
votes

I solved this problem my self and share it for others. if you create a solution starting with a dot-net-core project and add a dot-net framework project to it later, your vs 2017 may be confusing to use appropriate (System.Net.Http.dll) file for your dot net framework projects. for my dot net framework project visual studio use .dll with address : C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.netcore.app\2.1.0\ref\netcoreapp2.1\System.Net.Http.dll

but it should use this dll: C:\ProgramFiles\dotnet\sdk\NuGetFallbackFolder\system.net.http\4.3.0\lib\net46\System.Net.Http.dll

to solve this problem 1. go to your References section of your project and remove System.Net.Http.dll 2. add new dll file with right click on references and select Add Reference.. 3. click on browse and go to the second directory which i mentioned above.