Skip to content

Remove System.Net.Http.Formatting dependency  #52

Closed

Description

@Jericho

What do you think about removing the dependencies on Microsoft.AspNet.WebApi.Client and WinInsider.System.Net.Http.Formatting and replacing with our own code?

I did a preliminary review and it looks like we use the following classes from these packages:

  • MediaTypeFormatter: abstract class that describes a formatter (FluentClient already has a MediaTypeFormatter abstract class which is extremely similar)
  • MediaTypeFormatterCollection: very simple wrapper around Collection<MediaTypeFormatter> which makese sure the three default formatters are automatically added when a new instance of this collection is created
  • JsonMediaTypeFormatter: there used to be a class in the FluentClient project which was marked as obsolete and recently removed from the project. Maybe we could bring it back?
  • XmlMediaTypeFormatter: XML formatter
  • FormUrlMediaTypeFormatter: Form Url encoded formatter
  • ObjectContent: takes a formatter and an object and converts it into a string to be submitted

And also, the following extension methods:

  • CreateResponse(this HttpRequestMessage request, HttpStatusCode status);
  • ReadAsAsync<T>(this HttpContent content, MediaTypeFormatterCollection formatters);

I'm continuing my research to figure out if we use more classes and also working on a quick POC to show that it wouldn't be too complicated.

Activity

  1. Pathoschild commented on Feb 11, 2017

    @Pathoschild
    Owner

    I think compatibility with existing media type formatters is a big plus. What's the advantage to moving away from the main formatting library?

  2. Jericho commented on Feb 11, 2017

    @Jericho
    ContributorAuthor

    Sorry I forgot to mention the reason for my suggestion:

    To work around the fact that Microsoft's WebApi Client nuget package is not .NET STANDARD compliant we found a 3rd party package that provides same functionality. The drawback is that some resources are missing from this 3rd party nuget package which causes 4 unit tests to fail in the FluentHttpClient project. Not ideal but not a huge deal either. You and I are aware, and we know to disregard the 4 failing tests.

    However, I'm trying to use FluentHttpClient in one of my libraries and I'm getting more than 500 failing unit tests with the following error message:

    Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "System.Net.Http.Properties.Resources.resources" was correctly embedded or linked into assembly "WinInsider.System.Net.Http.Formatting" at compile time, or that all the satellite assemblies required are loadable and fully signed.

    I can't release my library with so many failing tests, To be honest, I suspect I have some underlying issue in my library but the real problem is obscured by the "missing resource" error message.

    That's why I'm suggesting we should get rid of WinInsider.System.Net.Http.Formatting and Microsoft WebApi Client.

  3. Jericho commented on Feb 12, 2017

    @Jericho
    ContributorAuthor

    I removed the netcoreapp1.0 section from my testing project project.son to force my unit tests to only be executed under net452 (thereby eliminating the WinInsider package for debugging purposes) and, as I suspected, there is an underlying problem which immediately became quite evident: I am attempting to use the FormUrlEncodedMediaTypeFormatter when submitting my requests and, as we discussed in #50 , this formatter can only be used to read responses and cannot be used for writing requests. This results in the following error: The configured formatter 'System.Net.Http.Formatting.FormUrlEncodedMediaTypeFormatter' cannot write an object of type 'List1'.`

    To summarize, there is an underlying error in my code which I need to resolve but the WinInsider obscured the problem by throwing an exception regarding missing resource.

  4. Jericho commented on Feb 12, 2017

    @Jericho
    ContributorAuthor

    I found a solution for my "underlying" problem (solution described in #50). So, as far as I'm concerned, removing the WinInsider package is not as urgent as I originally thought.

    However, the problem remains: when something goes wrong, the WinInsider package is unable to throw the appropriate exception due to missing resource and instead throws Could not find any resources appropriate for ... which obscures the real problem and makes it very hard for developers to figure out what's wrong.

    Is this something we can live with until Microsoft updates their WebApi Client?

  5. Pathoschild commented on Feb 12, 2017

    @Pathoschild
    Owner

    I think so. It's a workaround for .NET Core compatibility until Microsoft updates their packages, which will hopefully happen alongside .NET Core 2.0 in the next few months. I'd rather deal with that issue temporarily than remove support for the standard media type formatters.

  6. Jericho commented on Feb 12, 2017

    @Jericho
    ContributorAuthor

    I tend to agree with you. I freaked out when I saw 500+ of my unit tests failing and just a generic exception without any helpful message. But fortunately, I had an intuition about the underlying problem and I was able to figure out a workaround so I am not as alarmed as I was.

  7. added this to the 3.1 milestone on Feb 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions