Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The dependency microsoft.AspNet.WebApi.Client does not support framework .NETCoreApp, Version=v1.0 #1558

Closed
sravan1022 opened this issue Jun 8, 2016 · 35 comments

Comments

@sravan1022
Copy link

sravan1022 commented Jun 8, 2016

I created a .NETCore console application and using System.Net.Http.Since i need http.content to be included in my code, i installed Microsft.AspNet.WebApi.Client dependency using Package Manager Console.It installed successfully but i encountered an error as mentioned in the title. We know we need this dependency to add support for formatting and content negotiation for system.Net.Http . Can anyone help me in this issue ?
P.S I wanted to add this dependency because in my code i found this error : HttpContent doesnot contain a definition for 'ReadAsAsync' and no extension method 'ReadAsAsync' accepting a first argument of type HttpContent could be found when i am using response.Content.ReadAsAsync in my program.cs

@davidfowl
Copy link
Member

Did you create a new RC2 .NET Core project? I just tried, File -> New Project -> ASP.NET Core Web Application (.NET Core) -> Empty project. Added "Microsoft.AspNet.WebApi.Client": "5.2.3" to my project.json and it worked fine.

Did you perhaps covert an RC1 application?

@svick
Copy link
Contributor

svick commented Jun 10, 2016

@davidfowl That package supports portable-wp8+netcore45+net45+wp81+wpa81, but not netcoreapp1.0 (or some netstandard), so it will only work if you have imports with for example portable-net45+win8 in your project.json, which the default ASP.NET Core templates do.

As far as I can tell, that's an outdated package that probably shouldn't be used on ASP.NET Core.

@pranavkm
Copy link
Contributor

cc @dougbu \ @javiercn

@javiercn
Copy link
Member

You need to add an import in order to restore, there is a tracking bug for it http://aspnetwebstack.codeplex.com/workitem/2304

@davidfowl
Copy link
Member

davidfowl commented Jun 12, 2016

@svick I know, but the new project template has imports in them. I'm guessing you didn't make a new project.

@chadly
Copy link

chadly commented Aug 13, 2016

Even with "imports": "dnxcore50" in project.json (from the new project template), it still won't allow you to install Microsoft.AspNet.WebApi.Client:

Package Microsoft.AspNet.WebApi.Client 5.2.3 is not compatible with netcoreapp1.0 (.NETCoreApp,Version=v1.0). Package Microsoft.AspNet.WebApi.Client 5.2.3 supports:
      - net45 (.NETFramework,Version=v4.5)
      - portable-net45+netcore45+wp8+wp81+wpa81 (.NETPortable,Version=v0.0,Profile=wp8+netcore45+net45+wp81+wpa81)

One or more packages are incompatible with .NETCoreApp,Version=v1.0.

@davidfowl
Copy link
Member

imports dnxcore50 won't help with Microsoft.AspNet.WebApi.Client (it's not dnxcore50) compatible. You need to import one of the supported frameworks of the package. The only that will work in this case is "portable-net45+netcore45+wp8+wp81+wpa81" so

{
    "frameworks": {
        "imports" : ["dnxcore50", "portable-net45+netcore45+wp8+wp81+wpa81"]
    }
}

@chadly
Copy link

chadly commented Aug 13, 2016

Well, it allows me to restore now, but it still doesn't build.

"dependencies": {
    "System.Net.Http": "4.1.0",
    "Microsoft.AspNet.WebApi.Client": "5.2.3"
  }
error CS0433: The type 'IWebProxy' exists in both 'System.Net.Http.Primitives, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' and 'System.Net.Primitives, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

It looks like Microsoft.AspNet.WebApi.Client references Microsoft.Net.Http which is an older (deprecated?) version of System.Net.Http.

Am I just SOL if I want to reference these in a net core project?

@pranavkm
Copy link
Contributor

cc @dougbu

@dougbu
Copy link
Member

dougbu commented Aug 14, 2016

@chadly could you please try Microsoft.AspNet.WebApi.Client v5.2.2? That's what we use in MVC's WebApiCompatShim. See https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNetCore.Mvc.WebApiCompatShim/project.json#L26

Please let us know how this goes. If it works, would be good to know why; if it doesn't, we have the mystery of the Microsoft.AspNetCore.Mvc.WebApiCompatShim project building successfully.

@dougbu
Copy link
Member

dougbu commented Aug 14, 2016

Actually, ignore everything about package versions. I didn't read far enough in the project.json.

Instead add

      "imports": [
        "portable-net451+win8"
      ]

to the "netstandard1.6" entry under frameworks.

@chadly
Copy link

chadly commented Aug 14, 2016

Thanks @dougbu! That did it. For future reference, here is what worked for me:

"frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dnxcore50",
        "portable-net451+win8"
      ]
    }
  },
  "dependencies": {
    "System.Net.Http": "4.1.0",
    "Microsoft.AspNet.WebApi.Client": "5.2.3"
  }

@danielbsig
Copy link

@chadly Are you perhaps building on a Windows machine? What worked for you isn't working for me, at least not when I'm trying to build a console application on a mac.

@chadly
Copy link

chadly commented Sep 9, 2016

@danielbsig no, I was on compiling on Ubuntu

@chrisckc
Copy link

chrisckc commented Oct 25, 2016

I have just got this working a Mac using the following project.json

{
  "version": "1.0.0-*",
  "buildOptions": {
    "debugType": "portable",
    "emitEntryPoint": true
  },
  "dependencies": {
    "System.Net.Http": "4.1.0",
    "Microsoft.AspNet.WebApi.Client": "5.2.3",
    "Newtonsoft.Json": "9.0.1",
    "System.Runtime.Serialization.Primitives": "4.1.1-*",
    "System.Runtime.Serialization.Xml": "4.1.1-*"
  },
  "frameworks": {
    "netcoreapp1.0": {
      "dependencies": {
        "Microsoft.NETCore.App": {
          "type": "platform",
          "version": "1.0.0"
        }
      },
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ]
    }
  }
}

As a side note, i needed to add System.Runtime.Serialization.Xml when i added Newtonsoft.Json due to an issue with dependencies.

@daniel-desjardins
Copy link

I had exactly the same problem with an asp.net console app. The solution mentioned above by dougbu and chadly worked perfectly. The only difference in my environment is that my framework was netstandard1.6 not netcoreapp1.0, but it worked also

"frameworks": {
"netcoreapp1.0": { // for me netstandard1.6
"imports": [
"dnxcore50",
"portable-net451+win8"
]
}
},
"dependencies": {
"System.Net.Http": "4.1.0",
"Microsoft.AspNet.WebApi.Client": "5.2.3"
}

@SandeepApsingekar
Copy link

Hello Everyone,

I'm also working on the same thing. I want to make some httpclient calls to the server. using .net framework its easy to do. But using .net core I'm unable to do it. I would really appreciate if anyone can provide me any reference or an idea how to do it it will be really helpful.

To be more specific about my question, I would generalize it: That is,

I want to make HttpClient calls to the server, to request for the api to the server and get the response back from the server in the form of http requests and response.

Thank You!

I look forward for your response.

Best regards,

Sandeep

@Tratcher
Copy link
Member

@SandeepApsingekar you don't need Microsoft.AspNet.WebApi.Client for that, it just has fancy body serialization methods. System.Net.Http should be adequate for most needs.

@SandeepApsingekar
Copy link

SandeepApsingekar commented Jan 27, 2017

@Tratcher Hey Chris, Thank you for following up with me. In .NET framework I used to do that using Microsoft.AspNet.WebApi.Client. I would really appreciate your help if you can provide me with any online reference or a sample code which uses HttpClient class using .NET Core.

Thank You! I look forward for your response.

@Tratcher
Copy link
Member

What are you trying to do that doesn't work?

@SandeepApsingekar
Copy link

Hi
I actually had a problem with json deserialization in .net core. I somehow came through the issue by installing some packages in .net core. That problem is solved now.
But, What I'm trying to do is something like following code, my main aim is to do a client call which can invoke the api and get the response.
So I did some thing like this:
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("apiurl");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

Then I wrote a async get method for the response.

So, I wanted to know whether I'm going in right direction? I'm new to .net core.

Thank you!

Best Regards,
Sandeep Apsingekar

@Tratcher
Copy link
Member

That's a good start. next call var result = await client.GetStringAsync(); Then you can take that string and use Newtonsoft.Json to deserialize it.
http://www.newtonsoft.com/json/help/html/DeserializeObject.htm

@SandeepApsingekar
Copy link

Awesome! This link is really helpful has saved a lot of time. I really appreciate your help.
And, once I'm done with GET request, I would work on PostAsync. Is there any reference for post method using HttpClient.

Thank You!

Best Regards,

Sandeep

@shawnmclean
Copy link

Whats the fix for this on a project thats on vs2017 csproj format targeting netcoreapp1.1?

@malilevi1
Copy link

Hi all,

I've got the same error when I tried to add Microsoft.AspNet.WebApi.Client 5.2.3 from NuGet into a netStandard1.6 class library(in VS 2017).
The error text was: "Microsoft.AspNet.WebApi.Client 5.2.3 is not compatible with netstandard1.6"

I guess i have to modify the project.assets.json file but i don't really know where should I modify it.
I would really appreciate if anybody could help me solving this problem.

Thank you in advance!

Kind regards,
Levi

@kayjtea
Copy link

kayjtea commented May 11, 2017

If you can target .NETStandard 1.6, you might as well reference Microsoft.AspNetCore.Mvc.WebApiCompatShim directly (search nuget.org).

For those of us needing to target .NETStandard 1.4, this appears to work (assumes VS 2017): you need to have the PCL target fall back in the app csproj as well as all the csproj in between. I created my own Acme.WebApiCompatShim csproj, that looks like this (it has no code, just a shim):

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard1.4</TargetFramework>
    <PackageTargetFallback>portable-net451+win8</PackageTargetFallback>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.3" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="System.Runtime.Serialization.Xml" Version="4.3.0-*" />
    <PackageReference Include="System.Xml.XmlSerializer" Version="4.3.0-*" />
  </ItemGroup> 
</Project>

So if you have console app (netcoreapp1.1) => client library (netstandard 1.4) => Acme.WebCompatShim, you need

<PackageTargetFallback>portable-net451+win8</PackageTargetFallback>

in both the console app .csproj and the client library .csproj. And then in the client library you can do stuff like this again:

 Cat myCat = await response.Content.ReadAsAsync<Cat>();

@malilevi1
Copy link

Hi Kimberly,

Thank you for the information. I'll try your solution.

In the meantime i found some alternative solution here. and it worked for me.

Many thanks,
Levi

@vanillajonathan
Copy link
Contributor

It is being tracked here:
aspnet/Mvc#5822

It has been committed to Microsoft.AspNet.WebApi.Client 5.2.4 but not yet released.

HelloKitty added a commit to Endlessages/EndlessAges.LauncherService that referenced this issue May 24, 2017
Due to issues currently with Net Core we have to use a framework
fallback hack in the csproj to be able to add the nuget AspWebApiShim
project. To track this fault go to this issue:
dotnet/aspnetcore#1558
@darkguy2008
Copy link

@vanillajonathan I'm having the same issue in a project I'm working on. Nuget is still 5.2.3. Any date for 5.2.4? thanks!

@vanillajonathan
Copy link
Contributor

@darkguy2008 It will be out sometime during 2007 according to @Eilon.

I currently use the 5.2.4-alpha version hosted on MyGet.
https://www.myget.org/feed/aspnetwebstacknightly/package/nuget/Microsoft.AspNet.WebApi.Client

@sirajzarook
Copy link

sirajzarook commented Sep 28, 2017

I received similar error in a Console App (Net Core) built on TargetFramework 2.0. The issue was resolved immediately after installing the Microsoft.AspNetCore.Mvc.WebApiCompatShim -Version 2.0.0

`
netstandard2.0

`

@aspnet-hello
Copy link

This issue is being closed because it has not been updated in 3 months.

We apologize if this causes any inconvenience. We ask that if you are still encountering this issue, please log a new issue with updated information and we will investigate.

@ghost
Copy link

ghost commented Feb 5, 2018

As of Feb 2018, Microsoft.AspNet.WebApi.Client v5.2.4-preview1 is available on NuGet and is compatible with .Net Standard 2.0, project builds without warnings.

@sbrian26
Copy link

sbrian26 commented Feb 5, 2018

I install the preview... (nuget) then on compile...Error: Detected package downgrade: Microsoft.AspNet.WebApi.Client from 5.2.4-preview1 to 5.2.3. Reference the package directly from the project to select a different version......

What does it mean reference the package directly from the project?

@Eilon
Copy link
Member

Eilon commented Feb 5, 2018

@sbrian26 - you probably have another package in your app that is requesting a lower version of that package. You can add an explicit reference to that package version to force NuGet to pick the one you want.

@ghost ghost locked as resolved and limited conversation to collaborators Dec 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests