runtime: Error loading System.Buffers, Version=4.0.2.0 when using AspNet Core SignalR C# client in a .NET Framework 4.7.1 Web test

  1. clone to get the signalr chat sample at https://github.com/aspnet/SignalR-samples/tree/master/ChatSample
  2. open the solution, restore nuget package and Ctrl+F5 to run the service
  3. clone the webtest repro project at https://github.com/jeremymeng/WebTestRepro
  4. open WebAndLoadTestProject2.sln, restore then build the project. You will need the web test payload for your visual studio installation to support this type of project. image
  5. notice that the bin\Debug directory has 41 files
  6. now open the webtest.webtest file in visual studio. select Debug Test, pause before starting from the drop down

image

  1. under web test solution folder, check the most recent TestResults\<user_machineName timestamp>\Out folder. This is where the test is actually running. The folder only has 25 files under it. (This could be a bug in Web Test framework. I already logged a separate internal bug against VSTT team)
  2. copy all files from bin\Debug folder into the Out folder (skip existing)
  3. click Run button (the first button) to continue the web test image

Actual:

System.IO.InvalidDataException
  HResult=0x80131501
  Message=Invalid negotiation response received.
  Source=Microsoft.AspNetCore.Http.Connections.Common
  StackTrace:
   at Microsoft.AspNetCore.Http.Connections.NegotiateProtocol.ParseResponse(Stream content)
   at Microsoft.AspNetCore.Http.Connections.Client.HttpConnection.<NegotiateAsync>d__45.MoveNext()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Http.Connections.Client.HttpConnection.<GetNegotiationResponseAsync>d__52.MoveNext()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Http.Connections.Client.HttpConnection.<SelectAndStartTransport>d__44.MoveNext()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Http.Connections.Client.HttpConnection.<StartAsyncCore>d__41.MoveNext()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Http.Connections.Client.HttpConnection.<StartAsync>d__40.MoveNext()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.SignalR.Client.HttpConnectionFactory.<ConnectAsync>d__3.MoveNext()
   at Microsoft.AspNetCore.SignalR.Client.HttpConnectionFactory.<ConnectAsync>d__3.MoveNext()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.SignalR.Client.HubConnection.<StartAsyncCore>d__31.MoveNext()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.SignalR.Client.HubConnection.<StartAsync>d__24.MoveNext()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at iRel8.Service.WebTests.WebtestPlugins.SignalRJoinRoomPlugin.<PreRequest>d__0.MoveNext() in C:\github\jeremymeng\WebTestRepro\WebAndLoadTestProject2\SignalRJoinRoomPlugin.cs:line 16

Inner Exception 1:
TypeInitializationException: The type initializer for 'JsonArrayPool`1' threw an exception.

Inner Exception 2:
FileNotFoundException: Could not load file or assembly 'System.Buffers, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 3
  • Comments: 37 (16 by maintainers)

Most upvoted comments

Is there any information as to why 4.5.0 is causing issues?

The error people get when they hit this is just a symptom, and unfortunately it is a symptom that may be caused by many different root causes. The most common case why people hit this issue is because they are targetting .NET Framework in their app, and for one reason or another the tooling isn’t fully detecting that System.Buffers implementation targets .NET Standard, or it may detect it but it won’t include the required facades in the bin output folder because of custom project settings. That means that if you try to summarize most problems really happen because System.Buffers implementation targets .NET Standard, so what we did different in 4.5.1 was to provide an implementation in the package that also targets .NET Framework. With this, most projects that were having custom logic or settings causing this problem to arise should be fixed.

@sean-mcleish the only way we found was to configure reminding in the Web.config file, like this:

<runtime>
	<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
		<dependentAssembly>
			<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
			<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0"/>
		</dependentAssembly>
	</assemblyBinding>
	<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
		<dependentAssembly>
			<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
			<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
		</dependentAssembly>
	</assemblyBinding>
</runtime>

There is a new version of System.Buffers package that will ship some time this month which will make most of these problems go away. Package version will be 4.5.1.

I have the exact same problem, I tried everything I could find on the internet i’m completely clueless now…

My project is a WebTest project (Output Type of Class Library). I don’t get any warnings or errors when building the project in Visual Studio. There are no *.config files under bin\Debug even I have auto generate binding redirects on

image

1>CopyFilesToOutputDirectory:
1>  Copying file from "obj\Debug\WebAndLoadTestProject2.dll" to "bin\Debug\WebAndLoadTestProject2.dll".
1>  WebAndLoadTestProject2 -> C:\github\jeremymeng\WebTestRepro\WebAndLoadTestProject2\bin\Debug\WebAndLoadTestProject2.dll
1>  Copying file from "obj\Debug\WebAndLoadTestProject2.pdb" to "bin\Debug\WebAndLoadTestProject2.pdb".
1>
1>Build succeeded.
1>    0 Warning(s)
1>    0 Error(s)
1>
1>Time Elapsed 00:00:00.41
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

The config files I saw from fuslog are

LOG: Using application configuration file: C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\QTAgent32_40.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.

Okay, I found a temporary solution. The problem was that I dynamically loaded my web class library from a main application. The dynamic loading works by searching for all *.dll that implement a certain interface. The main application looks at its own *.exe.config and ignores the *.dll.config of the web class library. The current fix: add the redirects in the app.config of the main application. The desired fix: the main application also considers the *.dll.configs of all applications. I need to get a little more information about this.

Same issue observed on upgrading project to .NET framework 4.7.2 even after upgrading all nuget packages.

Error: 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) 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)

======== Even getting same error after upgrading System.Buffers to available versions on nuget 4.0.0/ 4.3.0 / 4.4.0 / 4.5.0

============

Below is my app.config file

<?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> </configSections> <startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" /></startup> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.1.4.0" newVersion="4.1.4.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.0.6.0" newVersion="4.0.6.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" /> </dependentAssembly> </assemblyBinding> </runtime> </configuration>