With the support of .Net Framework 4.0 ending we upgraded all our web clients to target the .Net Framework 4.6.1. Now that we are targeting the latest .Net Framework we can upgrade SignalR from 1.x to 2.x and be on the latest release.
I found this article (Upgrading SignalR 1.x Projects to version 2 By Patrick Fletcher) and followed the steps until Step 6: Right-click the solution, and select Add, New Item…. In the dialog, select Owin Startup Class. Name the new class Startup.cs. (Note: we are using VB.net)
I don’t see an option for Owin Startup Class?
In the comments of this question, I found an answer:
The OWIN Startup class is nothing but a typical .vb class. So just create a new class. Call it what ever you want and put this code into it and it will be the same as the template the startup class creates:
Imports Microsoft.AspNet.Identity <Assembly: OwinStartup(GetType(WebFormsIdentity.Startup))> Public Class Startup End Namespace
|
The following Imports were not valid for me and turns out are not needed, but, if you want to include them here’s how:
Imports Microsoft.AspNet.Identity
Imports Microsoft.Owin.Security.Cookies
Using NuGet, I fetched Microsoft.AspNet.Identity.Owin and fixed the missing references.
Broken Code
After the app compiled, ran it for the first time and ran across the error:
Error: Unable to get property ‘<<Hub Name>>’ of undefined or null reference
This usually means there is a naming issue, but, this was code that was working in 1.x, so that’s not it. After reading the section “Hub methods fail silently” lead me to the answer:
“Verify that the script references in your client are up to date, and that the
<i><span style="font-size: 10.0pt;">OwinStartup</span></i>
attribute for your Startup class has the correct class and assembly names for your project. Also, try opening up the hubs address (/signalr/hubs) in your browser; any error that appears will offer more information about what’s going wrong.”
While the web application was still targeting .Net Framework 4.0 and upgraded to Owin v2.1 we had to add the following line to the <appSettings> section to prevent an error when the web application loaded:
<appSettings>
…
<add key=“owin:AutomaticAppStartup“ value=“false“ />
</appSettings>
Made these changes to the <appSettings> section to fix the error:
<appSettings>
…
<add key=“owin:AppStartup“ value=“<<namespace>>.Startup, <<namespace>>“ />
<add key=“owin:AutomaticAppStartup“ value=“true“ />
</appSettings>
After making these changes SignalR 2.x was functioning again in our web application.
See Also