locked
System.Net.Http.UriExtensions wrong signature for .NET version RRS feed

  • Question

  • User64672722 posted

    I just noticed that the .NET 4.5 variant for the nuget package Mirosoft.AspNet.WebApi.Client 5.2.3 doesn't match the signature of the PCL variant.
    And it's causing a missing method exception at runtime when I call the Uri.ParseQueryString() method from a .NET 4.5 project...


    This is the PCL variant (which returns an HttpValueCollection)

    namespace System.Net.Http
    {
        public static class UriExtensions
        {
            public static HttpValueCollection ParseQueryString(this Uri address);
            public static bool TryReadQueryAs(this Uri address, Type type, out object value);
            public static bool TryReadQueryAs<T>(this Uri address, out T value);
            public static bool TryReadQueryAsJson(this Uri address, out JObject value);
        }
    }
    

    And this is the .NET variant: (which returns a NameValueCollection instead)

    namespace System.Net.Http
    {
        public static class UriExtensions
        {
            public static NameValueCollection ParseQueryString(this Uri address);
            public static bool TryReadQueryAs(this Uri address, Type type, out object value);
            public static bool TryReadQueryAs<T>(this Uri address, out T value);
            public static bool TryReadQueryAsJson(this Uri address, out JObject value);
        }
    }
    

    Is there any known workaround for this issue?

    EDIT:
    I created a simple test solution to reproduce the issue:
    https://www.dropbox.com/s/a586l05u2twa2vj/WebApiException.zip?dl=0
    It contains 3 projects:
    - WebApiException (Portable Library Profile 259) which exposes the CallUriParse() method... and it basically calls the Uri.ParseQueryString() offered by the Microsoft.AspNet.WebApi.Client package.
    - TestOk: references the Portable Library and calls the CallUriParse() method
    - TestKo: references the Portable Library and calls the CallUriParse() method... But in this case you'll get an exception, because in this project it has been installed the Microsoft.AspNet.WebApi.Client package, which has a different signature from the PCL version.

    Sunday, February 7, 2016 10:39 PM

Answers

  • User1814019480 posted

    Hi Marco,

    It is 'targetFramework' issue. Because PCL and .Net Framework using different version of 'System.Net.Http' DLL. By default, we used the .Net Framework file, e.g. its path is like this :

    C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.Net.Http.dll

    If we used the PortableClassLibrary, after install the webapi client, the project used the file like this:'C:\\...\packages\Microsoft.Net.Http.2.2.22\lib\portable-net40+sl4+win8+wp71+wpa81\System.Net.Http.dll'.

    If we want to use PCL DLL, we should change the targetFramework

      <package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net452" />

    to this:

      <package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="portable45-net45+win8+wp8" />

     in the packages.config file.

    About this issue, you could refer to this similar issue:

    https://github.com/fsprojects/Paket/issues/68

    If you'd like to get the more support about this issue, you can post it on this .Net Class Library forum:

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=netfxbcl

    Regards,

    Will

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 18, 2016 8:42 AM

All replies

  • User1814019480 posted

    hi sir,

    HttpValueCollection extends NameValueCollection. Please refer to this page(http://referencesource.microsoft.com/#System.Web/HttpValueCollection.cs,fde6b9ec5f1ed58a,references ).

    In this scenario, we can convert the  HttpValueCollection to a 'string' using 'HttpUtility.ParseQueryString'.

    Also, you can refer to this blog:

    http://leekelleher.com/2008/06/06/how-to-convert-namevaluecollection-to-a-query-string/

    And I have a question need confirmed: which type of project you occur the signature mismatch error? 

    Any update, please let me know.

    Regards,

    Will

    Tuesday, February 9, 2016 8:16 AM
  • User64672722 posted

    Hi Will,
    thank you for your reply, but unfortunately, this is a totally different issue.
    I get an Exception at runtime, when calling the ParseQueryString, due to the different signatures between the PCL and the .NET variants of the library WebAPI library.

    I created a simple test solution to reproduce the issue:
    https://www.dropbox.com/s/a586l05u2twa2vj/WebApiException.zip?dl=0
    It contains 3 projects:
    - WebApiException (Portable Library Profile 259) which exposes the CallUriParse() method... and it basically calls the Uri.ParseQueryString() offered by the Microsoft.AspNet.WebApi.Client package.
    - TestOk: references the Portable Library and calls the CallUriParse() method
    - TestKo: references the Portable Library and calls the CallUriParse() method... But in this case you'll get an exception, because in this project it has been installed the Microsoft.AspNet.WebApi.Client package, which has a different signature from the PCL version.

    I hope someone at Microsoft will look into this issue...
    Marco.

    Tuesday, February 9, 2016 2:12 PM
  • User64672722 posted
    Hi Will,
    did you had the chance to look at the test project?
    Or could point me to right place to report this issue?

    Thanks,
    Marco.


    Tuesday, February 16, 2016 12:40 PM
  • User1814019480 posted

    hi Marco,

    Sorry for delay. I will look into and reply you ASAP.

    Regards,

    Will

    Thursday, February 18, 2016 7:55 AM
  • User1814019480 posted

    Hi Marco,

    It is 'targetFramework' issue. Because PCL and .Net Framework using different version of 'System.Net.Http' DLL. By default, we used the .Net Framework file, e.g. its path is like this :

    C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.Net.Http.dll

    If we used the PortableClassLibrary, after install the webapi client, the project used the file like this:'C:\\...\packages\Microsoft.Net.Http.2.2.22\lib\portable-net40+sl4+win8+wp71+wpa81\System.Net.Http.dll'.

    If we want to use PCL DLL, we should change the targetFramework

      <package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net452" />

    to this:

      <package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="portable45-net45+win8+wp8" />

     in the packages.config file.

    About this issue, you could refer to this similar issue:

    https://github.com/fsprojects/Paket/issues/68

    If you'd like to get the more support about this issue, you can post it on this .Net Class Library forum:

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=netfxbcl

    Regards,

    Will

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 18, 2016 8:42 AM