Runtime: Could not load file or assembly 'System.Buffers, Version=4.0.2.0' on self hosting .Net Core API

Created on 11 Aug 2018  路  7Comments  路  Source: dotnet/runtime

I am trying to self host a .Net Core API from my application which targets to both 4.7.2 full framework and .Net Core 2.1. In my local development environment the API is running fine on both frameworks and when we tried to deploy the same in our Windows server and to run on framework 4.7.2, it throws the below error:

Exception: Could not load file or assembly 'System.Buffers, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Source: Microsoft.AspNetCore.Mvc.Core
Void AddMvcCoreServices(Microsoft.Extensions.DependencyInjection.IServiceCollection)
at Microsoft.Extensions.DependencyInjection.MvcCoreServiceCollectionExtensions.AddMvcCoreServices(IServiceCollection services)
at Microsoft.Extensions.DependencyInjection.MvcCoreServiceCollectionExtensions.AddMvcCore(IServiceCollection services)
at Microsoft.Extensions.DependencyInjection.MvcServiceCollectionExtensions.AddMvc(IServiceCollection services)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.ConfigureServices(IServiceCollection services)
at Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureApplicationServices()
at Microsoft.AspNetCore.Hosting.Internal.WebHost.Initialize()
at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
at Trane.OWS.Apps.WebAPI.TWebAPIApplication.DoStartup()
at Trane.Tracer.Apps.Framework.ApplicationManagement.TApplicationBase.Startup()
at Trane.Tracer.Apps.Framework.ApplicationManagement.TApplicationManager.StartApplications()
at Trane.Tracer.Apps.Framework.ApplicationManagement.TApplicationManager.Startup()

Both my local and server bin folder has same version(4.6.2) of System.Buffers library, however my local works fine and in server it throws the above error!

area-Infrastructure-libraries bug packaging

Most helpful comment

Have same issue with .NET Framework 4.8 project referencing System.Buffers indirectly as dependency of System.IO.Pipelines and System.Memory packages...

All 7 comments

@joperezr can you please take a look? Is it one of the known issues?

mm this is a weird one and might be hard to investigate, @ircaxn can you confirm that the machine you are running on has 4.7.2? Does your App.config or Web.config have any binding redirects to a different version of System.Buffers?

I found that the nuget packager has added dependent assembly configuration in my app.config file which points to specific version of System.Buffers. Thanks for your response.

Sorry to bump an old thread but I'm running into this while using the GraphQL nuget package - adding this to my web.config fixed it

<dependentAssembly>
        <assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="4.0.2.0" newVersion="4.0.3.0" />
</dependentAssembly>

Also running into this issue with .NET Framework 4.8. The build copies System.Buffers.dll to the output directory but it's version 4.6, not 4.0.2.

Also running into this issue with .NET Framework 4.8. The build copies System.Buffers.dll to the output directory but it's version 4.6, not 4.0.2.

Actually the file version is 4.6, but the assembly version is 4.0.3.0, see https://sitecore.stackexchange.com/questions/20379/could-not-load-file-or-assembly-system-buffers-or-one-of-its-dependencies

Have same issue with .NET Framework 4.8 project referencing System.Buffers indirectly as dependency of System.IO.Pipelines and System.Memory packages...

Was this page helpful?
0 / 5 - 0 ratings