doghappy / socket.io-client-csharp

socket.io-client implemention for .NET
MIT License
734 stars 126 forks source link

System.Threading.Tasks.Extensions dependency error #40

Closed luatnd closed 4 years ago

luatnd commented 4 years ago

Hi, many thanks for the library, I've just installed SocketIOClient@1.0.3.12 (runtime version is v4.0.30319) via NuGet, I could build it successfully. But when I run the app, my app when crashed because of this error:

System.IO.FileNotFoundException: Could not load file or assembly 'System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.
File name: 'System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
   at System.Threading.Channels.SingleConsumerUnboundedChannel`1..ctor(Boolean runContinuationsAsynchronously)
   at System.Threading.Channels.Channel.CreateUnbounded[T](UnboundedChannelOptions options)
   at Websocket.Client.WebsocketClient..ctor(Uri url, Func`3 connectionFactory)
   at SocketIOClient.SocketIO.ConnectAsync()
   at cBot.Robots.BitQSignalExecutor.<initRemoteSignal>d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()

The program try to load System.Threading.Tasks.Extensions, Version=4.2.0.0 but the installed version is System.Threading.Tasks.Extensions, Version=4.5.4, and release history has no version 4.2.0 !!

I'm using .NET 4.7.2 and add netstandard as reference.

here my code, copied from your example:

using System.Threading.Tasks.Extensions; // ==> VS IDE highlight that no Extensions in System.Threading.Tasks

   // --- here my class's function
    public async void initRemoteSignal()
    {
      const string TEST_CHANNEL = "chat_message";
      var client = new SocketIO("http://localhost:3000");
      client.ConnectTimeout = TimeSpan.FromSeconds(5);

      client.On(TEST_CHANNEL, args =>
      {
        string text = JsonConvert.DeserializeObject<string>(args.Text);
        Console.WriteLine(args.Text);
      });

      client.OnConnected += async () =>
      {
        for (int i = 0; i < 5; i++)
        {
          await client.EmitAsync(TEST_CHANNEL, i.ToString());
          await Task.Delay(1000);
        }
        await client.EmitAsync("close", "close");
      };
      client.OnClosed += Client_OnClosed;
      await client.ConnectAsync();
    }

I checked the project's references and sawSystem.Threading.Tasks.Extensions has already been there.

I think I got library interference issue, but I'm a new to C# .net so I dont know how to resolve this issue. Any suggestion are welcome!

luatnd commented 4 years ago

My temporary solution is to downgrade to SocketIOClient@1.0.3.1 to exclude the Websocket.Client. Higher versions that have Websocket.Client causing crashed. I would stay at SocketIOClient@1.0.3.1 at least it can work :)

doghappy commented 4 years ago

I created a clean new project and I didn't get any errors.

csproj

<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>

App.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <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.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>

package.config

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Newtonsoft.Json" version="12.0.3" targetFramework="net472" />
  <package id="SocketIOClient" version="1.0.3.12" targetFramework="net472" />
  <package id="System.Collections" version="4.3.0" targetFramework="net472" />
  <package id="System.Reactive" version="4.3.2" targetFramework="net472" />
  <package id="System.Runtime.CompilerServices.Unsafe" version="4.5.2" targetFramework="net472" />
  <package id="System.Threading.Channels" version="4.7.0" targetFramework="net472" />
  <package id="System.Threading.Tasks.Extensions" version="4.5.3" targetFramework="net472" />
  <package id="System.ValueTuple" version="4.5.0" targetFramework="net472" />
  <package id="Websocket.Client" version="4.2.3" targetFramework="net472" />
</packages>
luatnd commented 4 years ago

Thanks, I'll check it and try to figure out the cause.

emvivre commented 4 years ago

The solution proposed by @doghappy does not work with me. The only approach which works is to downgrade to the SocketIOClient@1.0.3.1 version. Thanks @luatnd .

luatnd commented 4 years ago

@emvivre Do you have a minimal reproduction to help doghappy face the issue? I'm writing a proj base on a platform so it requires setting up a whole development env to reproduce the issue, cannot make a minimal project!

doghappy commented 4 years ago

Thanks for the information provided, I will fix this problem

doghappy commented 4 years ago

Please upgrade to 1.0.3.13-alpha, please tell me if it is fixed.

Install-Package SocketIOClient -Version 1.0.3.13-alpha
luatnd commented 4 years ago

Thanks, the same error, sometime the error is for System.Threading.Tasks.Extensions, sometime is for System.Reactive:

System.IO.FileNotFoundException: Could not load file or assembly 'System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.
File name: 'System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
   at System.Threading.Channels.SingleConsumerUnboundedChannel`1..ctor(Boolean runContinuationsAsynchronously)
   at System.Threading.Channels.Channel.CreateUnbounded[T](UnboundedChannelOptions options)
   at Websocket.Client.WebsocketClient..ctor(Uri url, Func`3 connectionFactory)
   at SocketIOClient.SocketIO.ConnectAsync()
   at cAlgo.Robots.BitQSignalExecutor.<initRemoteSignal>d__a.MoveNext() in c:\Users\Neo\Documents\cAlgo\Sources\Robots\BitQ Signal Executor\BitQ Signal Executor\BitQ Signal Executor.cs:line 150
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
System.IO.FileNotFoundException: Could not load file or assembly 'System.Reactive, Version=4.4.0.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263' or one of its dependencies. The system cannot find the file specified.
File name: 'System.Reactive, Version=4.4.0.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263'
   at SocketIOClient.SocketIO.ConnectAsync()
   at cAlgo.Robots.BitQSignalExecutor.<initRemoteSignal>d__a.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
luatnd commented 4 years ago

I'm trying to clone the source code and add it to my project without success, I have no C# experience so the language version, the lamda syntax ... prevent me to build -.-

doghappy commented 4 years ago

You don't need to clone the source code, please try to install missing dependencies, If you have already installed, please try to upgrade to the latest version

System.Threading.Tasks.Extensions and System.Reactive

luatnd commented 4 years ago

After updating those above dependencies, even Websocket.Client, I faced the same error. Tried with both 1.0.3.13-alpha and 1.0.3.13

doghappy commented 4 years ago

This issue has been fixed in the latest version 2.0.0. If it has not been fixed, please reopen it.