Reputation: 416
I have two console applications:
Following code demonstrates how I initialize SignalR server:
public void Configuration(IAppBuilder app)
{
HttpConfiguration webApiConfiguration = ConfigureWebApi();
app.UseWebApi(webApiConfiguration);
app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
app.MapSignalR(new HubConfiguration() { EnableDetailedErrors = true });
}
And this is how I am trying to establish connection with the server from the client application:
public void Run()
{
HubConnection hubConnection = new HubConnection(this.hubConnectionURL);
hubConnection.TraceLevel = TraceLevels.All;
hubConnection.TraceWriter = Console.Out;
remoteServerHubProxy = hubConnection.CreateHubProxy("SignalRHub");
remoteServerHubProxy.On<Int32, MyModel>("MethodName", new Action<Int32, MyModel>((lid, model) => this.MethodName(lid, model)));
hubConnection.Start().Wait();
}
Whenever Start().Wait()
executes, following exception happens clientside:
System.AggregateException was unhandled
HResult=-2146233088
Message=One or more errors occurred.
Source=mscorlib
StackTrace:
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.Wait()
...
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
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.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.TimeoutException
HResult=-2146233083
Message=Transport timed out trying to connect
InnerException:
The interesting part is, that this exception happens only during first ever connection attemp from the client (first connection attempt after server app restart, thats it). If I restart the client or launch another client instance, then it connects fine and SignalR communication works smoothly.
Anyone knows what I am doing wrong here?
I am also attaching SignalR logs both from server and client.
Server log:
SignalR.PerformanceCounterManager Error: 0 : Performance counter failed to load:
System.InvalidOperationException: The requested Performance Counter is not a cu
stom counter, it has to be initialized as ReadOnly.
at System.Diagnostics.PerformanceCounter.InitializeImpl()
at System.Diagnostics.PerformanceCounter..ctor(String categoryName, String co
unterName, String instanceName, Boolean readOnly)
at Microsoft.AspNet.SignalR.Infrastructure.PerformanceCounterManager.LoadCoun
ter(String categoryName, String counterName, String instanceName, Boolean isRead
Only)
-- Client attempts to connect at this point --
SignalR.ReflectedHubDescriptorProvider Warning: 0 : Some of the classes from ass
embly "System.Web.Helpers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf
3856ad364e35" could Not be loaded when searching for Hubs. [C:\WINDOWS\Microsoft
.Net\assembly\GAC_MSIL\System.Web.Helpers\v4.0_2.0.0.0__31bf3856ad364e35\System.
Web.Helpers.dll]
Original exception type: ReflectionTypeLoadException
Original exception message: Unable to load one or more of the requested types. R
etrieve the LoaderExceptions property for more information.
Client log:
12:03:07.1550299 - null - ChangeState(Disconnected, Connecting)
12:03:10.8516530 - 51a4e258-e99d-4cb3-ae14-6db438b38f95 - WS Connecting to: ws:/
/localhost:50439/signalr/connect?clientProtocol=1.4&transport=webSockets&connect
ionData=[{"Name":"SignalRHub"}]&connectionToken=AQAAANCMnd8BFdERjHoAwE%2FCl%2BsB
AAAAnx4jsfsOuUa3e0rrW2DifQAAAAACAAAAAAAQZgAAAAEAACAAAAA1tTgi2Va0M73SCNJ9d0%2FKsU
IxJ2aa2MrFGOPAWa7ToAAAAAAOgAAAAAIAACAAAABDorXWYymqxI%2BWurCF6ugPmi7YtifHOo9mqJNF
m2Cw8DAAAACgotOAC75ljMQHhlhFOUsrU4DQBJJ0HvVDP1VGDNfIc9onQ8niU3cmFHA%2BnUHsVExAAA
AAsdFd7ZtqMuHBBl%2FuT%2Bg0hDG5OWmEeJKDZWvkHuOPUHXUVM2S0fTRsDW1BdOg4bai4w3LvbYqqK
dYFqdY8KimvA%3D%3D
12:03:15.9569154 - 51a4e258-e99d-4cb3-ae14-6db438b38f95 - Auto: Failed to connec
t to using transport webSockets. System.TimeoutException: Transport timed out tr
ying to connect
12:03:15.9569154 - 51a4e258-e99d-4cb3-ae14-6db438b38f95 - SSE: GET http://localh
ost:50439/signalr/connect?clientProtocol=1.4&transport=serverSentEvents&connecti
onData=[{"Name":"SignalRHub"}]&connectionToken=AQAAANCMnd8BFdERjHoAwE%2FCl%2BsBA
AAAnx4jsfsOuUa3e0rrW2DifQAAAAACAAAAAAAQZgAAAAEAACAAAAA1tTgi2Va0M73SCNJ9d0%2FKsUI
xJ2aa2MrFGOPAWa7ToAAAAAAOgAAAAAIAACAAAABDorXWYymqxI%2BWurCF6ugPmi7YtifHOo9mqJNFm
2Cw8DAAAACgotOAC75ljMQHhlhFOUsrU4DQBJJ0HvVDP1VGDNfIc9onQ8niU3cmFHA%2BnUHsVExAAAA
AsdFd7ZtqMuHBBl%2FuT%2Bg0hDG5OWmEeJKDZWvkHuOPUHXUVM2S0fTRsDW1BdOg4bai4w3LvbYqqKd
YFqdY8KimvA%3D%3D
12:03:20.9764573 - 51a4e258-e99d-4cb3-ae14-6db438b38f95 - Auto: Failed to connec
t to using transport serverSentEvents. System.TimeoutException: Transport timed
out trying to connect
12:03:20.9764573 - 51a4e258-e99d-4cb3-ae14-6db438b38f95 - LP Connect: http://loc
alhost:50439/signalr/connect?clientProtocol=1.4&transport=longPolling&connection
Data=[{"Name":"SignalRHub"}]&connectionToken=AQAAANCMnd8BFdERjHoAwE%2FCl%2BsBAAA
Anx4jsfsOuUa3e0rrW2DifQAAAAACAAAAAAAQZgAAAAEAACAAAAA1tTgi2Va0M73SCNJ9d0%2FKsUIxJ
2aa2MrFGOPAWa7ToAAAAAAOgAAAAAIAACAAAABDorXWYymqxI%2BWurCF6ugPmi7YtifHOo9mqJNFm2C
w8DAAAACgotOAC75ljMQHhlhFOUsrU4DQBJJ0HvVDP1VGDNfIc9onQ8niU3cmFHA%2BnUHsVExAAAAAs
dFd7ZtqMuHBBl%2FuT%2Bg0hDG5OWmEeJKDZWvkHuOPUHXUVM2S0fTRsDW1BdOg4bai4w3LvbYqqKdYF
qdY8KimvA%3D%3D
12:03:25.9915200 - 51a4e258-e99d-4cb3-ae14-6db438b38f95 - Auto: Failed to connec
t to using transport longPolling. System.TimeoutException: Transport timed out t
rying to connect
12:03:25.9965215 - 51a4e258-e99d-4cb3-ae14-6db438b38f95 - Disconnected
12:03:25.9965215 - 51a4e258-e99d-4cb3-ae14-6db438b38f95 - Transport.Dispose(51a4
e258-e99d-4cb3-ae14-6db438b38f95)
12:03:25.9965215 - 51a4e258-e99d-4cb3-ae14-6db438b38f95 - Closed
Upvotes: 5
Views: 2136
Reputation: 416
The problem was with the library System.Web.Helpers
which is part of ASP.NET MVC installation. As soon as I set the CopyLocal=true
for this specific assembly in the References
, my problem went away.
Upvotes: 1