System.Net.Http Error After Visual Studio 15.8.1 (2017) Update

Today we started getting an error from three web applications.  Two were web services and one was an ASP.NET MVC website.  The error was:

Could not load file or assembly ‘System.Net.Http, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ or one of its dependencies. The located assembly’s manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

The error was occurring on this standard line in the global.asax file:

WebApiConfig.Register(GlobalConfiguration.Configuration)

Looking at the trace statements on the error page, there was a mention of a binding redirect, which I recall seeing in the web.config of the site.  That section in the web config looked like:

<runtime>

    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

      <dependentAssembly>

        <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>

        <bindingRedirect oldVersion="0.0.0.0-2.2.29.0" newVersion="2.2.29.0"/>

      </dependentAssembly>

    </assemblyBinding>

  </runtime>

This config block had been in place since December, 2015.  The block seems to have been added by a NuGet package at the same time, possibly with a Framework version upgrade.

However it originally ended up there, removing the config block allowed the sites to launch again.  It’s unknown why this started happening after a Visual Studio upgrade.

Batch Applying MetaFLAC ReplayGain Tags To Recursive Album Folders

I’ve been ignoring PowerShell for a very long time, even though I know it is the future of scripting.  The structure of the language is very foreign, with all of the pipe options.  But I muddled through the examples I found online and came up with my first usable PowerShell script.

The purpose of the script is to iterate recursively through a folder structure and generate a command statement using all the files in each folder.  In this case, MetaFLAC is being called with arguments to apply ReplayGain tags to all the files in a folder.  To do this effectively, you have to pass all the file names in the folder on one command line.  This is so the overall album sound level can be calculated.

Without further introduction, here is the script:

<#
    This script applies album-level and file-level
    ReplayGain tags to FLAC album folders recursively

    Example usage from PS command line:
    .\ReplayGain.ps1 -root:"c:\music\FLAC"

    MetaFLAC.exe must be in same folder or in environment PATH
#>

Param(
    #Fully-qualified path to top-level folder.
    [string]$root
    )

Function CallMetaFLAC($d){
    Write-Host "Processing" ($d | Get-ChildItem -Filter "*.flac").length "files in" $d
    
    if (($d | Get-ChildItem -Filter "*.flac").length -gt 0){
        $args="–add-replay-gain "

        foreach ($f in ($d | Get-ChildItem -Filter "*.flac" | % {$_.FullName}) ){
            $args=$args + """$f"" "
            }

        Start-Process "metaflac.exe" $args -Wait -NoNewWindow
    }

    # Process Subfolders
    foreach($dd in $d | Get-ChildItem -Directory){
        CallMetaFLAC $dd
        }
}

Write-Host "Starting in $root"
Write-Host

CallMetaFLAC $root

Write-Host
Write-Host "Ending"