Skip to content

Emitted refs wrong for 4.5.1 System.Net.Http.Formatting.dll #68

Closed

Description

@bartelink

I had to hand-edit my fsproj targetting 4.5.1 an inconsistent DLL was present at runtime until I added a .1 to the Condition:

<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And $(TargetFrameworkVersion) == 'v4.5.1'">
  <ItemGroup>
    <Reference Include="System.Net.Http.Formatting">
      <HintPath>..\packages\Microsoft.AspNet.WebApi.Client\lib\net45\System.Net.Http.Formatting.dll</HintPath>
      <Private>True</Private>
      <Paket>True</Paket>
    </Reference>
  </ItemGroup>

Packet.references:

Microsoft.AspNet.WebApi

Packet dependencies:

source "http://nuget.org/api/v2"

nuget "Microsoft.AspNet.WebApi" ">= 5"

Built from source, commit 50cb2a9

Dumping and running for now. Will do proper diagnosis and/or upodate this issue when I determine more later and/or tomorrow

Activity

  1. forki commented on Sep 9, 2014

    @forki
    Member

    It creates the following:

      <Choose>
        <When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And $(TargetFrameworkVersion) == 'v4.5'">
          <ItemGroup>
            <Reference Include="System.Net.Http.Formatting">
              <HintPath>..\..\packages\Microsoft.AspNet.WebApi.Client\lib\net45\System.Net.Http.Formatting.dll</HintPath>
              <Private>True</Private>
              <Paket>True</Paket>
            </Reference>
          </ItemGroup>
        </When>
        <When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And $(TargetFrameworkVersion) == 'v4.5'">
          <ItemGroup>
            <Reference Include="System.Net.Http.Formatting">
              <HintPath>..\..\packages\Microsoft.AspNet.WebApi.Client\lib\portable-wp8+netcore45+net45+wp81+wpa81\System.Net.Http.Formatting.dll</HintPath>
              <Private>True</Private>
              <Paket>True</Paket>
            </Reference>
          </ItemGroup>
        </When>
        <When Condition="$(TargetFrameworkIdentifier) == '.NETFramework'">
          <ItemGroup>
            <Reference Include="System.Net.Http.Formatting">
              <HintPath>..\..\packages\Microsoft.AspNet.WebApi.Client\lib\portable-wp8+netcore45+net45+wp81+wpa81\System.Net.Http.Formatting.dll</HintPath>
              <Private>True</Private>
              <Paket>True</Paket>
            </Reference>
          </ItemGroup>
        </When>
      </Choose>
    

    that's strange. .NET 4.5 is in two path. .NET 4.5.1 should be covered by the last When condition.

    /cc @agross

  2. agross commented on Sep 9, 2014

    @agross
    Contributor

    As per this overview portable-wp8+netcore45+net45+wp81+wpa81 is related to PCLs. So the second When should be generated with another condition and the third one should not be generated at all. As soon as the folder below lib starts with portable we need to translate the strings separated by + into a framework profile (see link). Sadly the one used here is not documented and Google results very sparse.

  3. agross commented on Sep 9, 2014

    @agross
    Contributor

    I created a PCL project to check what's set for it:

    TargetPlatformIdentifier = Portable
    TargetPlatformVersion = 7.0
    TargetFrameworkIdentifier = .NETPortable
    TargetFrameworkProfile = Profile259
    

    Profile259 == lib/portable-net45+netcore45+wpa81+wp8+MonoAndroid1+MonoTouch1

  4. bartelink commented on Sep 9, 2014

    @bartelink
    MemberAuthor

    @forki @agross The problem is that the app was not happy with the PCL one at runtime, i.e. the first one needs to succeed.

    Didn't analyze why yet.

    Looking...

  5. bartelink commented on Sep 9, 2014

    @bartelink
    MemberAuthor

    The one that's:

    assembly: TargetFramework(".NETPortable,Version=v4.5,Profile=Profile259", FrameworkDisplayName = ".NET Portable Subset")
    

    Fails because it has stuff missing, triggering YSOD:

    Line 25: 
    Line 26:     member x.Application_Start() =
    Line 27:         GlobalConfiguration.Configure <| Action<_> registerWebApi
    

    And you can guess the rest:

    [TypeLoadException: Could not load type 'System.Net.Http.Formatting.FormUrlEncodedMediaTypeFormatter' from assembly 'System.Net.Http.Formatting, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.]
       System.Web.Http.HttpConfiguration.DefaultFormatters(HttpConfiguration config) +0
       System.Web.Http.HttpConfiguration..ctor(HttpRouteCollection routes) +303
       System.Web.Http.GlobalConfiguration.<CreateConfiguration>b__0() +100
       System.Lazy`1.CreateValue() +416
       System.Lazy`1.LazyInitValue() +152
       System.Lazy`1.get_Value() +75
       System.Web.Http.GlobalConfiguration.get_Configuration() +35
       System.Web.Http.GlobalConfiguration.Configure(Action`1 configurationCallback) +108
       Compose.Web.Global.Application_Start() in C:\<...>\Global.asax.fs:27
    
    [HttpException (0x80004005): Could not load type 'System.Net.Http.Formatting.FormUrlEncodedMediaTypeFormatter' from assembly 'System.Net.Http.Formatting, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.]
       System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +9905705
       System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +118
       System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
       System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336
       System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296
    
    [HttpException (0x80004005): Could not load type 'System.Net.Http.Formatting.FormUrlEncodedMediaTypeFormatter' from assembly 'System.Net.Http.Formatting, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.]
       System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9885060
       System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
       System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
    
  6. bartelink commented on Sep 9, 2014

    @bartelink
    MemberAuthor

    @agross @forki Obv I dont directly use the class; it's loaded by something indirect. Right now, it's just raw WebApi.AspNet

    If you want I can spider it's dependencies, but looking at @agross ' detailed research elsewhere I doubt I'm going to be efficient locating the required inputs!

  7. agross commented on Sep 9, 2014

    @agross
    Contributor

    That's right, Paket should get you the first one and have Conditions for the portable libs that's excluding them for your 4.5.1 project.

  8. forki commented on Sep 16, 2014

    @forki
    Member

    can you please test if this is fixed in 0.2.0-alpha009

  9. bartelink commented on Sep 16, 2014

    @bartelink
    MemberAuthor

    Will do; Hopefully tomorrow...

  10. bartelink commented on Sep 17, 2014

    @bartelink
    MemberAuthor

    @forki Looking great in 0.2.0-alpha011 - Thanks!

  11. bartelink commented on Sep 17, 2014

    @bartelink
    MemberAuthor

    One more thing which I'll log here for triage...

    I didnt have an explicit reference to System.Net.Http. Not sure how that came about, but me deleting it manually is a def possibility.

    When one runs an install in that state, Paket puts in a reference to one in a packages\Microsoft.Net.Http\lib\net40 dir as a default.

    This triggers the warn:

    C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(1697,5): warning MSB3277: Found conflicts between different versions of the same dependent assembly that could not be resolved. These reference conflicts are listed in the build log when log verbosity is set to detailed.

    The inconsistency is that most of the stuff is being (correctly) picked up from a net45 folder, inc 2 dlls that are dependent on System.Net.Http.dll.

    So, to repro the problem, either

    • start with 4.0 and add Microsoft.Net.Http package
      • install will add the Paket stuff
      • switch to 4.5/4.5.1 will confuse matters
    • start with 4.5/4.5.1 (which will already include the System.Net.Http simple framework reference

    And to fix the problem, the Paket-induced ref to the one in packages\Microsoft.Net.Http\lib\net40 should happen under net40 but not under 45 or 451

  12. forki commented on Sep 19, 2014

    @forki
    Member

    wow this one is really fucked up.

    We generate:

      <Choose>
        <When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And $(TargetFrameworkVersion) == 'v4.0'">
          <ItemGroup>
            <Reference Include="System.Net.Http">
              <HintPath>..\..\packages\Microsoft.Net.Http\lib\net40\System.Net.Http.dll</HintPath>
              <Private>True</Private>
              <Paket>True</Paket>
            </Reference>
          </ItemGroup>
        </When>
        <When Condition="$(TargetFrameworkIdentifier) == '.NETFramework'">
          <ItemGroup>
            <Reference Include="System.Net.Http">
              <HintPath>..\..\packages\Microsoft.Net.Http\lib\net40\System.Net.Http.dll</HintPath>
              <Private>True</Private>
              <Paket>True</Paket>
            </Reference>
          </ItemGroup>
        </When>
      </Choose>
    

    because we find System.Net.Http.dll in net40.

    It doesn't exist for net45. BUT the net45 folder exists.

    image

    image

    anybody an idea for a clever rule?

  13. bartelink commented on Sep 20, 2014

    @bartelink
    MemberAuthor

    @forki you pasted the same screenshot twice but I've got the problem burned into my retina....

    The problem here is that

    • in 4.0, install needs to both reference its own thing and remove any 4.5+-supplied reference pathed reference
    • in 4.5+ install needs to ensure that a normal reference is present and/or allow it to be present

    I'd be surprised if NuGet handled this correctly (i.e. I'd say the wizards can gen a 4.0 or a 4.5 app but just package install/reinstall is not going to allow you to compile and run correctly without intevention re adding/removing references).

    I think the disconnect here is that NuGet and .nupkgs assume you derive a platform at the point of installation and then one 'set' wins per area and can't really see how Paket can handle most things correctly if it doesn't work that way too (I realize of course that the correct in-order-of-folder insertion that Paket manages is yet another thing in play to make it a pretty hard problem).

    This same disconnect manifests itself in the problem in the source installation where redundant folders remain present.

    But, back to the problem: one critical outcome Paket needs to deliver is to be able to make idempotent changes to the proj files.

    I don't think it makes any sense to have Paket start understanding the relationship between builtin System.Net.Http vs Nuget ones prior to 4.5 iff it can be avoided.

    For now, I think if Paket can make a project level determination of the platform and/or when flattening that down per file generate a leg of a <Choose> that has no file, it'll be fine. The thing that's not intrinisically dealt with then is the need to add/remove the ref to the intrinsic one as one switches to/from 4.5 to 4.0. But that can be a separate issue and is pretty corner casey I say!

  14. forki commented on Sep 20, 2014

    @forki
    Member

    could you please create a working references XML snippet and copy it here? I'm a bit lost.

  15. bartelink commented on Sep 20, 2014

    @bartelink
    MemberAuthor

    I'm even more lost now that I've examined things :)

    Web.config has:

    <system.web>
        <compilation debug="true" targetFramework="4.5.1" />
        <httpRuntime targetFramework="4.5.1" />
      </system.web>
      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-5.2.2.0" newVersion="5.2.2.0" />
          </dependentAssembly>
        </assemblyBinding>
      </runtime>
    

    Paket gave me:

      <Choose>
        <When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And $(TargetFrameworkVersion) == 'v4.0'">
          <ItemGroup>
            <Reference Include="System.Net.Http">
              <HintPath>..\packages\Microsoft.Net.Http\lib\net40\System.Net.Http.dll</HintPath>
              <Private>True</Private>
              <Paket>True</Paket>
            </Reference>
          </ItemGroup>
        </When>
        <When Condition="$(TargetFrameworkIdentifier) == '.NETFramework'">
          <ItemGroup>
            <Reference Include="System.Net.Http">
              <HintPath>..\packages\Microsoft.Net.Http\lib\net40\System.Net.Http.dll</HintPath>
              <Private>True</Private>
              <Paket>True</Paket>
            </Reference>
          </ItemGroup>
        </When>
      </Choose>
    

    I'm pretty sure the wizard gave me and/or I added:

    <Reference Include="System.Net.Http" />
    

    BUT it's not there - I'm guessing it's due to doing an install --hard (other explanation is I deleted the ref in reproing?)

    If I remove the bindingRedirect, I get:

    Could not load file or assembly 'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)<

    For reproing, I'm not doing anything interesting - I have a pretty vanilla WebApi app (no MVC) from the F# MVC 5 template.

    The wiz and/or me via Sln Assembly Refs can add:

    <Reference Include="System.Net.Http" />
    

    The Paket bits don't case a problem - the Paket one is ignored and doesnt go to outdir

    But the redirect is needed.

    I should clarify the bit that actually triggers the error is hyperlinkr, which is built against WebApi 1 (vs 2 in 4.5 and 2.2 on nuget latest)

    The line of code is:

    open Ploeh.Hyprlinkr
    

    ...

            let link2 =  RouteLinker(this.Request).GetUri( fun (x: ProductsController) -> x.Get id)
    

    If you don't ref System.Net.Http, the this.Request bit won't compile.

    NB For me the actual repro of the downstream problem is a red herring though - the fact there's a compiler warning is enough (even though that's because hyprlinkr wants a different version). The bottom line is that the compilation needs to be against the new dll, not the net40 one.

  16. bartelink commented on Sep 20, 2014

    @bartelink
    MemberAuthor

    Hang on, VS changed the Paket genned bit to:

    <Choose>
        <When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And $(TargetFrameworkVersion) == 'v4.0'">
          <ItemGroup>
            <Reference Include="System.Net.Http">
              <HintPath>..\packages\Microsoft.Net.Http\lib\net40\System.Net.Http.dll</HintPath>
              <Private>True</Private>
              <Paket>True</Paket>
            </Reference>
          </ItemGroup>
        </When>
        <When Condition="$(TargetFrameworkIdentifier) == '.NETFramework'" />
      </Choose>
    

    When I hit delete on the ref (OK, that makes sense whenI think about it).

    Then I added it back via add references.

    Now paket install (built yesterday) removes all reference to the net40 one (which would be wrong if I switched back to 4.0 but works for me).

    If I delete and do a paket install, leaving at 4.5.1, Paket puts in:

    <Choose>
        <When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And $(TargetFrameworkVersion) == 'v4.0'">
          <ItemGroup>
            <Reference Include="System.Net.Http">
              <HintPath>..\packages\Microsoft.Net.Http\lib\net40\System.Net.Http.dll</HintPath>
              <Private>True</Private>
              <Paket>True</Paket>
            </Reference>
          </ItemGroup>
        </When>
        <When Condition="$(TargetFrameworkIdentifier) == '.NETFramework'">
          <ItemGroup>
            <Reference Include="System.Net.Http">
              <HintPath>..\packages\Microsoft.Net.Http\lib\net40\System.Net.Http.dll</HintPath>
              <Private>True</Private>
              <Paket>True</Paket>
            </Reference>
          </ItemGroup>
        </When>
      </Choose>
    

    In summary, Paket is behaving pretty predictably as previously described.

    It's 'Just' a matter of figuring out whether the NuGet package and/or tooling perhaps encodes the fact that for target FW 4.5/4.5.1 the standard reference assembly should be used instead (I think one can specify Non-NuGet FW Assembly refs per target fw?). Either way a net40 should only be used for 4.5/4.5.1 iff there are no 4.5 / 4.5.1 libs at all (and same rule for sources etc.)

  17. bartelink commented on Sep 20, 2014

    @bartelink
    MemberAuthor

    NPE (hadnt tried it - its great!) confirms that there are conditional framework dependency items in the package

         <frameworkAssemblies>
          <frameworkAssembly assemblyName="System.Net.Http" targetFramework=".NETFramework4.5" />
          <frameworkAssembly assemblyName="System.Net.Http.WebRequest" targetFramework=".NETFramework4.5" />
          <frameworkAssembly assemblyName="System.Net.Http" targetFramework="MonoTouch0.0" />
          <frameworkAssembly assemblyName="System.Net.Http" targetFramework="MonoAndroid0.0" />
        </frameworkAssemblies>
    

    Then the remaining bit is to only install the lib content for a single target framework.

    Want me to close this and log specific issues (happy for anyone else to do it either)?

  18. forki commented on Sep 21, 2014

    @forki
    Member

    Yes please close this monster thread and create a new one with simple repro steps

  19. bartelink commented on Sep 21, 2014

    @bartelink
    MemberAuthor

    @forki OK, might not get time till a good bit later but will do

  20. bartelink commented on Sep 22, 2014

    @bartelink
    MemberAuthor

    Split into:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions