title: Signalr Core for ASP.net core 2.0 not working no matter what i try
body: <p>trying to follow microsoft's video w/  Mikael Mengistu, Jon Galloway, Maria Naggaga.</p>
  
  <p><a href="https://channel9.msdn.com/Shows/Code-Conversations/Introduction-to-SignalR-Core-with-Mikael-Mengistu" rel="nofollow noreferrer">https://channel9.msdn.com/Shows/Code-Conversations/Introduction-to-SignalR-Core-with-Mikael-Mengistu</a></p>
  
  <p>0.
  here is what my machine looks like.
  dotnet --version 2.0.0-preview2-006497
  runtime Microsoft .NET Core Shared Framework Host Version : 2.0.0-preview2-25407-01
  Visual Studio 2017 15.3 MVC Web Project with Docker Support</p>
  
  <p>here is the code repo of my attempt.
  github.com/zhimaqiao1/SRcoreWorking
  the signalr-client i had to edit myself to get something at least half working.</p>
  
  <ol>
  <li><p>started with vanilla mvc template 
  which targets netcoreapp2.0
  and PackageReference Microsoft.AspNetCore.All" Version="2.0.0-preview2-final"</p></li>
  <li><p>tried to add signalr core nuget packages
  from dotnet.myget.org/F/aspnetcore-ci-dev/api/v3/index.json
  ( this is the nuget repo seen in the video. )
  Microsoft.AspNetCore.SignalR Version=1.0.0-alpha1-26462</p></li>
  <li><p>The nuget UI in visual studio warns me that it has to upgrade some things to
  2.1.0-Preview1-26462</p></li>
  </ol>
  
  <p>.... without adding a line of code i just f5 and get a runtime error ( not a build error )</p>
  
  <p>at the line </p>
  
  <pre><code>  public static IWebHost BuildWebHost(string[] args) =&gt;
      WebHost.CreateDefaultBuilder(args)
          .UseStartup&lt;Startup&gt;()
          .Build();
  
  the error is 
  
      System.MissingMethodException occurred HResult=0x80131513
      Message=Method not found: 
      System.IDisposable.Microsoft.Extensions.Options.IOptionsMonitor`1.OnChange(System.Action`1&lt;!0&gt;)'
      StackTrace:
      Microsoft.Extensions.Logging.Console.ConsoleLoggerProvider..ctor(IOptionsMonitor`1 options)
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProvider provider)
  </code></pre>
  
  <ol start="4">
  <li>I take a theoretical guess that some extension method coming from signalr and being applied to something in aspnet core 2.0 is not looking for that thing thats not there.   So i add another signalr package just for the heck of it.
  Microsoft.AspNetCore.SignalR.Http Version=1.0.0-alpha1-26462</li>
  </ol>
  
  <p>when i press f5 i get a different error!!   ( woohoo making progress )</p>
  
  <pre><code>   System.MissingMethodException occurred
    HResult=0x80131513
    Message=Method not found: 'System.Collections.Generic.Dictionary`2&lt;System.String,System.Object&gt; Microsoft.Extensions.Configuration.IConfigurationBuilder.get_Properties()'.
    Source=&lt;Cannot evaluate the exception source&gt;
    StackTrace:
  &lt;Cannot evaluate the exception stack trace&gt;
  </code></pre>
  
  <p>5</p>
  
  <pre><code>I continue to add signalr packages hoping something will work
  Microsoft.AspNetCore.SignalR" Version="1.0.0-alpha1-26462" 
  Microsoft.AspNetCore.SignalR.Client" Version="1.0.0-alpha1-26462" 
  Microsoft.AspNetCore.SignalR.Common" Version="1.0.0-alpha1-26462"
  Microsoft.AspNetCore.SignalR.Http" Version="1.0.0-alpha1-26462"
  Microsoft.AspNetCore.SignalR.Redis" Version="1.0.0-alpha1-26462"
  
  
  
  still i get the 
     System.MissingMethodException occurred
    HResult=0x80131513
    Message=Method not found: 'System.Collections.Generic.Dictionary`2&lt;System.String,System.Object&gt; Microsoft.Extensions.Configuration.IConfigurationBuilder.get_Properties()'.
  </code></pre>
  
  <p>6.</p>
  
  <p>I remembered back when i added the first signalr package from the repo in the video
  dotnet.myget.org/F/aspnetcore-ci-dev/api/v3/index.json</p>
  
  <p>it wanted to upgrade some things from my PackageReference Microsoft.AspNetCore.All" Version="2.0.0-preview2-final"
  to 2.1.0-Preview1-26462</p>
  
  <p>so i went around searching for Microsoft.AspNetCore.All 2.1.0-Preview1-26462 just to cut to the chase...
  i found it in the same repo from the video
  dotnet.myget.org/F/aspnetcore-ci-dev/api/v3/index.json</p>
  
  <p>I removed all the signalr packages and cleaned out my nuget cache with 
  .\nuget.exe locals all -clear</p>
  
  <p>then i pressed f5
  ( remember this is still vanilla mvc aspnetcore 2.0 template.  no code has been added by me yet )</p>
  
  <p>I get the following exception.....</p>
  
  <p>System.IO.FileLoadException occurred
    HResult=0x80131040
    Message=Could not load file or assembly 'System.Diagnostics.DiagnosticSource, Version=4.0.2.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
    Source=
    StackTrace:
     at Microsoft.AspNetCore.Hosting.WebHostBuilder.BuildCommonServices(AggregateException&amp; hostingStartupErrors)
     at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
     at WebApplication1.Program.BuildWebHost(String[] args) in D:\org\projects\fogbridge3\ActorModelDojo\src\Solution2\WebApplication1\Program.cs:line 21
     at WebApplication1.Program.Main(String[] args) in D:\org\projects\fogbridge3\ActorModelDojo\src\Solution2\WebApplication1\Program.cs:line 17</p>
  
  <ol start="7">
  <li>I tried so many things to get past this error just coming from 
  Microsoft.AspNetCore.All" Version="2.1.0-preview1-26462" </li>
  </ol>
  
  <p>i tried to add the projects one by one but eventually all roads lead through Microsoft.AspNetCore.Hosting which depends on System.Diagnostics.DiagnosticSource
  and it would never let me downgrade to satisfy the runtime error.
  i tried to reference another project with downlevel System.Diagnostics.DiagnosticSource 4.0.2.1
  I tried to reference the dlls directly.
  there are many version located under C:\Users\gracie.nuget\packages\system.diagnostics.diagnosticsource
  I looked in 
  C:\Users\gracie.nuget\packages\system.diagnostics.diagnosticsource\4.0.0\lib and found the following directories
  net46
  netstandard1.1
  netstandard1.3
  portable-net45+win8+wpa81</p>
  
  <p>all yeilded the error from visual studio...
  the reference is invalid or not supported.</p>
  
  <p>i did a verbose build and spotted the following lines </p>
  
  <pre><code>     Dependency "System.Diagnostics.DiagnosticSource, Version=4.0.2.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51".
           Could not resolve this reference. Could not locate the assembly "System.Diagnostics.DiagnosticSource, Version=4.0.2.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
               For SearchPath "C:\Users\gracie\.nuget\packages\microsoft.aspnetcore.hosting\2.1.0-preview1-26462\lib\netstandard2.0".
               Considered "C:\Users\gracie\.nuget\packages\microsoft.aspnetcore.hosting\2.1.0-preview1-26462\lib\netstandard2.0\System.Diagnostics.DiagnosticSource.winmd", but it didn't exist.
               Considered "C:\Users\gracie\.nuget\packages\microsoft.aspnetcore.hosting\2.1.0-preview1-26462\lib\netstandard2.0\System.Diagnostics.DiagnosticSource.dll", but it didn't exist.
               Considered "C:\Users\gracie\.nuget\packages\microsoft.aspnetcore.hosting\2.1.0-preview1-26462\lib\netstandard2.0\System.Diagnostics.DiagnosticSource.exe", but it didn't exist.
  </code></pre>
  
  <p>so i manually copied it from C:\Users\gracie.nuget\packages\system.diagnostics.diagnosticsource\4.0.0\lib\netstandard1.3
  to C:\Users\gracie.nuget\packages\microsoft.aspnetcore.hosting\2.1.0-preview1-26462\lib\netstandard2.0\
  the effort was ignored.</p>
  
  <p>I then added it directly to the csproj 
  PackageReference Include="Microsoft.AspNetCore.All" Version="2.1.0-preview1-26462"
  PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.0.2.1"</p>
  
  <p>I received 8 errors saying the same thing...
  Severity    Code    Description Project File    Line    Suppression State
  Error   NU1605  Detected package downgrade: System.Diagnostics.DiagnosticSource from 4.4.1 to 4.0.2.1. Reference the package directly from the project to select a different version. 
   WebApplication1 (>= 1.0.0) -> Microsoft.AspNetCore.All (>= 2.1.0-preview1-26462) -> Microsoft.AspNetCore.Diagnostics (>= 2.1.0-preview1-26462) -> System.Diagnostics.DiagnosticSource (>= 4.4.1) 
   WebApplication1 (>= 1.0.0) -> System.Diagnostics.DiagnosticSource (>= 4.3.0)   WebApplication1 D:\org\projects\fogbridge3\ActorModelDojo\src\Solution2\WebApplication1\WebApplication1.csproj  1</p>
  
  <p>NOTHING WORKED.</p>
  
  <p>So i went back to ground zero.
   i simply added the original 
   then i stripped out as much MVC code as possible but nothing worked.
   i still needed the following line and that line errored out.</p>
  
  <pre><code>   public static IWebHost BuildWebHost(string[] args) =&gt;
      WebHost.CreateDefaultBuilder(args)
          .UseStartup&lt;Startup&gt;()
          .Build();
  </code></pre>
  
  <p>I even went back to aspnetcore 1.1 style verbose hosting code.</p>
  
  <p>still errored as before when adding just a single signalr package  ( ANY PACKAGE or ALL THE PACKAGES ). </p>
  
  <p>AFTER FOUR LONG DAYS... FOUR DAYS!!!!!!!</p>
  
  <p>I came up on a combination that built and seemed to run at runtime.</p>
  
  <p>PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0-preview2-final" 
  PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.0.0-preview2-25794" 
  PackageReference Include="Microsoft.AspNetCore.SignalR.Http" Version="1.0.0-preview2-25794"</p>
  
  <p>I got both signalr packages from a new repo ( not the one in the video )
  aspnetcore-release at myget
  dotnet.myget.org/F/aspnetcore-release/api/v3/index.json</p>
  
  <p>This default MVC website ran perfectly
  But i had yet to add any signalr code yet.</p>
  
  <p>so i configured my services</p>
  
  <p>public void ConfigureServices(IServiceCollection services)
      {</p>
  
  <pre><code>    //services.AddMvc();
      services.AddSockets();
      //services.AddSocketsCore();
      services.AddSignalRCore( );
  }
  </code></pre>
  
  <p>configured my pipeline</p>
  
  <pre><code>        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
          {
              app.UseStaticFiles();
  
              app.UseSignalR(routes =&gt;
              {
                  routes.MapHub&lt;Chat&gt;("chat");
              });
  
  }
  </code></pre>
  
  <p>created my hub</p>
  
  <p>public class Chat : Hub
  {</p>
  
  <pre><code>public override async Task OnConnectedAsync()
  {
      await Clients.Client(Context.ConnectionId).InvokeAsync("connectionmade", "connection made dude");
  
      await base.OnConnectedAsync();
  }
  
  public async Task Send(string message)
  {
      await Clients.All.InvokeAsync("Send",  message);
  }
  </code></pre>
  
  <p>}</p>
  
  <pre><code>installed my client into node_modules 
  npm install signalr-client --registry dotnet.myget.org/F/aspnetcore-ci-dev/npm --save-dev
  
   copied the signalr-client.js into 
  /lib/signalr-client/dist/browser/signalr-client.js
  </code></pre>
  
  <p>created a file called chat.html at the root of wwww folder with the following excerpt of code ....</p>
  
  
  
  <p>
      let transportType = signalR.TransportType[getParameterByName('transport')] || signalR.TransportType.WebSockets;</p>
  
  <pre><code>let http = new signalR.HttpConnection(`http://${document.location.host}/chat`, { transport: transportType });
  let connection = new signalR.HubConnection(http);
  </code></pre>
  
  <p>cleared the nuget cache </p>
  
  <pre><code>.\nuget.exe locals all -clear
  </code></pre>
  
  <p>double checked the packages
  PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0-preview2-final" 
  PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.0.0-preview2-25794"
  PackageReference Include="Microsoft.AspNetCore.SignalR.Http" Version="1.0.0-preview2-25794" </p>
  
  <p>the pressed f5.
  and BOOM!!!!     SyntaxError: Unexpected token c in JSON at position 0  </p>
  
  <p>upon further inspection
  the signalr-client makes it to line 171
  .....let negotiatePayload = yield this.httpClient.options(this.url);
  and negotiatePayload resolves to something that looks like a connectionid  f35c2377-5477-413b-a861-e41c57ee0e92</p>
  
  <p>the next line 172 in the signalr-client 
  ......let negotiateResponse = JSON.parse(negotiatePayload);
  crashes with the following exception 
  Failed to start the connection. SyntaxError: Unexpected number in JSON at position 1</p>
  
  <p>so i start mucking around changing to the signalr-client to be more lenient.
  after overcoming a few more errors like TypeError: availableTransports is undefined</p>
  
  <p>I finally get a breakpoint hit on the .net side!!!!!!
  and some good looking console log messages...
  WebSocket connected to ws://localhost:55592/chat?id=f7c96a55-0266-452d-b071-3b04b7794aad  signalr-client.js:575:21
  (WebSockets transport) data received: {"invocationId":"1","type":1,"target":"connectionmade","nonBlocking":true,"arguments":["connection made dude"]}</p>
  
  <p>here is the edited functionality in the signalr-client....</p>
  
  <pre><code>startInternal() {
      return __awaiter(this, void 0, void 0, function* () {
          try {
              let negotiatePayload = yield this.httpClient.options(this.url);
              //let negotiateResponse = JSON.parse(negotiatePayload);
              let negotiateResponse = negotiatePayload;
              //this.connectionId = negotiateResponse.connectionId;
              this.connectionId = negotiateResponse;
              // the user tries to stop the the connection when it is being started
              if (this.connectionState == ConnectionState.Disconnected) {
                  return;
              }
              this.url += (this.url.indexOf("?") == -1 ? "?" : "&amp;") + `id=${this.connectionId}`;
              //this.transport = this.createTransport(this.options.transport, negotiateResponse.availableTransports);
  
              this.transport = new Transports_1.WebSocketTransport();
  
  
              this.transport.onDataReceived = this.onDataReceived;
              this.transport.onClosed = e =&gt; this.stopConnection(true, e);
              yield this.transport.connect(this.url);
  </code></pre>
  
  <p>eventually though i gave up because subsequent message sending errors out  with 
  Connection closed with error: Error: Websocket closed with status code: 1011 ()</p>
  
  <p>something to do with the following code .....</p>
  
  <pre><code>        function parseMessage(input, position) {
              var offset = position;
              // Read the length
              var [lenStr, offset] = splitAt(input, ":", offset);
              // parseInt is too leniant, we need a strict check to see if the string is an int
              if (!LengthRegex.test(lenStr)) {
                  throw new Error(`Invalid length: '${lenStr}'`);    &lt;------ throws this error..
  where..
  input = "{"invocationId":"5","type":1,"target":"connectionmade","nonBlocking":true,"arguments":["connection made dude"]}    
  </code></pre>
  
  <p>PLEASE SOMEBODY HELP!!!
  Am i using the wrong signalr-client???</p>
  
  <p>The repo from where i got the signalr packages 
      dotnet.myget.org/F/aspnetcore-release/api/v3/index.json
      PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.0.0-preview2-25794"
      PackageReference Include="Microsoft.AspNetCore.SignalR.Http" Version="1.0.0-preview2-25794"     </p>
  
  <pre><code>doesnt seem to have a client for me.
  i tried npm install signalr-client --registry https://dotnet.myget.org/F/aspnetcore-release/api/v3/index.json --save-dev
  but that doesnt work so i went with the original one from the video
  npm install signalr-client --registry dotnet.myget.org/F/aspnetcore-ci-dev/npm --save-dev
  
  i also tried the one from aspnet core github site https://github.com/aspnet/SignalR
  </code></pre>
  
  <p>Finally i downloaded the source from <a href="https://github.com/aspnet/SignalR" rel="nofollow noreferrer">https://github.com/aspnet/SignalR</a>
  and couldnt build it.
  the chat sample wouldnt run. </p>
  
  <p>Can someone please help me.  MY business partner is telling me to dump asp.net core and signalr  and go with linux alternatives.
  Our business model requires us to use docker and hence asp.net core running in linux .
  we cannot use Signalr for .NET framework.</p>
  
  <p>here is what my machine looks like.</p>
  
  <p>sdk ..... 
  dotnet --version
  2.0.0-preview2-006497   </p>
  
  <p>runtime
  Microsoft .NET Core Shared Framework Host
  Version  : 2.0.0-preview2-25407-01      </p>
  
  <p>Visual Studio 2017 15.3 MVC Web Project with Docker Support</p>