chroma-sdk/Colore

RestClient modifies BaseUrl on HttpClient which is forbidden

guidoarkesteijn opened this issue · 6 comments

Expected Behavior

When calling CreateRestAsync(appInfo); it should return an IChroma instance.

Current Behavior

When calling CreateRestAsync(appInfo); it throws an exception.

Unhandled Exception: System.AggregateException: One or more errors occurred. (This instance has already started one or more requests. Properties can only be modified before sending the first request.) ---> System.InvalidOperationException: This instance has already started one or more requests. Properties can only be modified before sending the first request.
   at System.Net.Http.HttpClient.CheckDisposedOrStarted()
   at System.Net.Http.HttpClient.set_BaseAddress(Uri value)
   at Colore.Rest.RestApi.InitializeAsync(AppInfo info) in C:\projects\colore\src\Colore\Rest\RestApi.cs:line 157
   at Colore.Implementations.ChromaImplementation.InitializeAsync(AppInfo info) in C:\projects\colore\src\Colore\Implementations\ChromaImplementation.cs:line 263
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at Colore.Implementations.ChromaImplementation..ctor(IChromaApi api, AppInfo info) in C:\projects\colore\src\Colore\Implementations\ChromaImplementation.cs:line 120
   at Colore.ColoreProvider.CreateAsync(AppInfo info, IChromaApi api) in C:\projects\colore\src\Colore\ColoreProvider.cs:line 112
   at Colore.ColoreProvider.CreateRestAsync(AppInfo info, Uri endpoint) in C:\projects\colore\src\Colore\ColoreProvider.cs:line 100
   at Colore.ColoreProvider.CreateRestAsync(AppInfo info, String endpoint) in C:\projects\colore\src\Colore\ColoreProvider.cs:line 76
   at chroma_plugin.Program.StartApp() in C:\Project\Program.cs:line 49
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location where exception was thrown ---
   at System.Threading.ThreadPoolWorkQueue.Dispatch()

Possible Solution

I think internally the HttpClient is being changed but because the call is already started it throws an exception.

Steps to Reproduce (for bugs)

  1. Checkout the sample project found on github: https://github.com/guidoarkesteijn/colore-dotnetcore
  2. Run it with dotnet run. (version 2.2)

Context

Setting up an working environment in dotnet core 2.2 with the starting guide..

Your Environment

  • Version of Colore used: 6.0.0-rc0003
  • SDK mode (Native or REST API): Rest Api
  • Synapse version installed: Version 3.4.216.21216
  • Chroma SDK version in use: (razer/chromasdk) {"core":"3.01.00","device":"3.01.00","version":"3.01.00"}
  • Operating System and version (e.g. Windows 10 x64): Windows 10 x64 (dotnet core 2.0)
  • Link to your project (if available): https://github.com/guidoarkesteijn/colore-dotnetcore

Also tried it in Visual Studio 2017 with a newly created WPFApp, following the starting guide but it throws the same exception.

I checkout the source code of Colore and tried running it with a sample project attached. When stepping through the code I noticed that the InitializeAsync method logs an exception. Because the response data does not return a session or URI in the response data. It returns the following JSON instead:
{"device_supported":"keyboard | mouse | headset | mousepad | keypad | chromalink","result":87}

I've pushed a commit that should fix the "modifying properties" error. The wrong return data is something else though, I've sent a question to Razer asking what's up with that, it's not returning what the documentation is saying it should return.

Thanks @Sharparam for the quick response.

Could this be a change in the new Synapse/ChromaSDK? On SDK 2.10 I don't get the error.

I only tested this on the 3.0 version. I think Razer installs the 3.0 version by default nowadays. Which is apparently still in beta.

I split the SDK-related bug to a separate issue #258.

The BaseUrl-related bug in this issue seems fixed on my end, so I'll close this one (fix available in currently released 6.0.0-rc4 and all future releases).