7

I'm getting an assembly binding error with System.Buffers when working with Sitecore 9.2. What could be causing this? With assembly binding logging enabled, it appears the issue is a binding redirect expecting assembly version 4.0.3.0, but finding 4.0.2.0.

Could not load file or assembly 'System.Buffers' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

=== Pre-bind state information ===
LOG: DisplayName = System.Buffers
 (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: System.Buffers | Domain ID: 2
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/inetpub/wwwroot/habitat.dev.local/
LOG: Initial PrivatePath = C:\inetpub\wwwroot\habitat.dev.local\bin
LOG: Dynamic Base = C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\a31ecb9a
LOG: Cache Base = C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\a31ecb9a
LOG: AppName = 5a56a8f2
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\inetpub\wwwroot\habitat.dev.local\web.config
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/root/a31ecb9a/5a56a8f2/System.Buffers.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/root/a31ecb9a/5a56a8f2/System.Buffers/System.Buffers.DLL.
LOG: Attempting download of new URL file:///C:/inetpub/wwwroot/habitat.dev.local/bin/System.Buffers.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\inetpub\wwwroot\habitat.dev.local\bin\System.Buffers.dll
LOG: Entering download cache setup phase.
LOG: Assembly Name is: System.Buffers, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
LOG: A partially-specified assembly bind succeeded from the application directory. Need to re-apply policy.
LOG: Using application configuration file: C:\inetpub\wwwroot\habitat.dev.local\web.config
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Redirect found in application configuration file: 4.0.2.0 redirected to 4.0.3.0.
LOG: Post-policy reference: System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
LOG: GAC Lookup was unsuccessful.
LOG: The post-policy assembly reference requires probing again.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/root/a31ecb9a/5a56a8f2/System.Buffers.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/root/a31ecb9a/5a56a8f2/System.Buffers/System.Buffers.DLL.
LOG: Attempting download of new URL file:///C:/inetpub/wwwroot/habitat.dev.local/bin/System.Buffers.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\inetpub\wwwroot\habitat.dev.local\bin\System.Buffers.dll
LOG: Entering download cache setup phase.
LOG: Assembly Name is: System.Buffers, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
WRN: Comparing the assembly name resulted in the mismatch: Build Number
ERR: The assembly reference did not match the assembly definition found.
ERR: Setup failed with hr = 0x80131040.
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
13

Certain functionality in Sitecore 9.2 requires an explicit dependency on System.Buffers 4.5.0. However some dependencies for Sitecore 9.2 have a transitive (indirect) dependency on System.Buffers 4.4.0. Thus, Sitecore 9.2 includes this bindingRedirect:

  <dependentAssembly>
    <assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" xmlns="urn:schemas-microsoft-com:asm.v1"/>
    <bindingRedirect oldVersion="4.0.2.0-4.0.3.0" newVersion="4.0.3.0" xmlns="urn:schemas-microsoft-com:asm.v1"/>
  </dependentAssembly>

Depending on your build configuration, certain Sitecore NuGet references can result in System.Buffers 4.4.0 publishing to your web root.

To avoid this, your options are:

  1. Add an explicit reference in your solution to System.Buffers 4.5.0 and ensure it is deployed. If you are following a Helix Solution Architecture, you will likely need to add this reference in your Project layer, and ensure your solution dependencies / build order are set up such that your Project layer publishes last.
  2. Configure your build to not deploy System.Buffers. If you are using Sitecore TDS, you can configure it to Exclude or Include assemblies when building to your web root. If you are using Helix Publishing Pipeline, it has the capability to exclude assemblies as well.

Note on Versioning of System.Buffers

You may be confused by the assembly versions based on the package versions, and when looking at the file properties of System.Buffers.dll, where the version appears to be 4.6. The version of the assembly itself does not match, as can be seen with a bit of PowerShell.

PS> (get-item .\System.Buffers.dll).VersionInfo.FileVersion
4.6.26515.06
PS> [System.Reflection.Assembly]::LoadFile("$pwd\System.Buffers.dll").GetName().Version
Major  Minor  Build  Revision
-----  -----  -----  --------
4      0      3      0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.