aspnetcore icon indicating copy to clipboard operation
aspnetcore copied to clipboard

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

Open sravan1022 opened this issue 10 years ago • 35 comments

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

sravan1022 avatar Jun 08 '16 05:06 sravan1022

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?

davidfowl avatar Jun 09 '16 14:06 davidfowl

@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.

svick avatar Jun 10 '16 15:06 svick

cc @dougbu \ @javiercn

pranavkm avatar Jun 10 '16 17:06 pranavkm

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

javiercn avatar Jun 10 '16 17:06 javiercn

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

davidfowl avatar Jun 12 '16 15:06 davidfowl

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.

chadly avatar Aug 13 '16 00:08 chadly

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"]
    }
}

davidfowl avatar Aug 13 '16 00:08 davidfowl

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?

chadly avatar Aug 13 '16 00:08 chadly

cc @dougbu

pranavkm avatar Aug 13 '16 03:08 pranavkm

@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 avatar Aug 14 '16 22:08 dougbu

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.

dougbu avatar Aug 14 '16 22:08 dougbu

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"
  }

chadly avatar Aug 14 '16 23:08 chadly

@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.

danielbsig avatar Sep 09 '16 07:09 danielbsig

@danielbsig no, I was on compiling on Ubuntu

chadly avatar Sep 09 '16 14:09 chadly

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.

chrisckc avatar Oct 25 '16 21:10 chrisckc

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" }

daniel-desjardins avatar Oct 27 '16 23:10 daniel-desjardins

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

SandeepApsingekar avatar Jan 27 '17 15:01 SandeepApsingekar

@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.

Tratcher avatar Jan 27 '17 17:01 Tratcher

@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.

SandeepApsingekar avatar Jan 27 '17 17:01 SandeepApsingekar

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

Tratcher avatar Jan 27 '17 22:01 Tratcher