【问题标题】:System.AggregateException in SignalR when calling Connection.Start调用 Connection.Start 时 SignalR 中的 System.AggregateException
【发布时间】:2016-10-29 05:28:32
【问题描述】:

我有一个服务器和客户端项目。每个项目都在它自己的解决方案中,并托管在 TFS 上。我正在尝试制作一个简单的 SignalR 程序。

客户端是一个WPF客户端,有一个打开的窗口->用户点击一个按钮,被带到一个主页窗口。此窗口会自动连接到服务器。

public partial class HomeWindow : Window
 {
    public Player player { get; set; }
    public IHubProxy _hub { get; set; }
    string url = @"http://localhost:63346/";
    public HubConnection Connection { get; set; }


    public HomeWindow()
    {
        InitializeComponent();
        //This is a mock player. The player class should actually be generated from data pulled
        //from the database when the player authenticates
        player = new Player(150);
        Connection = new HubConnection(url);
        _hub = Connection.CreateHubProxy("MyHub");
        Connection.Start().Wait(); //Here is where the error comes from
    }

在 Connection.Start.Wait();行,编译器给出 System.AggregateException。 (InnerException StatusCode:500,ReasonPhrase:“内部服务器错误”,版本:1.1,内容:System.Net.Http.StreamContent,标头: { 日期:2016 年 10 月 29 日星期六 05:24:40 GMT 服务器:Microsoft-HTTPAPI/2.0 内容长度:0 })

因为内部异常提到了错误 500,所以这里也是服务器信息。

[HubName("MyHub")]
class MyHub : Hub
{

}

程序.cs

    static void Main(string[] args)
    {
        string url = @"http://localhost:63346/";
        using (WebApp.Start<Startup>(url))
        {
            Console.WriteLine(string.Format("Server running at {0}", url));
            Console.ReadLine();
        }
    }

Startup.cs

class Startup
{
    public void Configuration(IAppBuilder app)
    {
        app.UseCors(CorsOptions.AllowAll);
        app.MapSignalR();
    }
}

完整的异常详情

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 Client.HomeWindow..ctor() in C:\Users\Zachary\Documents\Visual Studio 2015\Projects\Matchmaking Client\Client\HomeWindow.xaml.cs:line 37
   at Client.MainWindow.button_Click(Object sender, RoutedEventArgs e) in C:\Users\Zachary\Documents\Visual Studio 2015\Projects\Matchmaking Client\Client\MainWindow.xaml.cs:line 30
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
   at System.Windows.Controls.Primitives.ButtonBase.OnClick()
   at System.Windows.Controls.Button.OnClick()
   at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
   at System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e)
   at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
   at System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)
   at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
   at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
   at System.Windows.Input.InputManager.ProcessStagingArea()
   at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
   at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
   at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
   at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at System.Windows.Application.Run(Window window)
   at System.Windows.Application.Run()
   at Client.App.Main()
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
   at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
   at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
   at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
   at System.Activator.CreateInstance(ActivationContext activationContext)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
   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: 
   HResult=-2146233088
   Message=StatusCode: 500, ReasonPhrase: 'Internal Server Error', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
  Date: Sat, 29 Oct 2016 16:08:23 GMT
  Server: Microsoft-HTTPAPI/2.0
  Content-Length: 0
}
   Source=Microsoft.AspNet.SignalR.Client
   StackTrace:
        at Microsoft.AspNet.SignalR.Client.Http.DefaultHttpClient.<>c__DisplayClass5_0.<Get>b__1(HttpResponseMessage responseMessage)
        at Microsoft.AspNet.SignalR.TaskAsyncHelper.<>c__DisplayClass31_0`2.<Then>b__0(Task`1 t)
        at Microsoft.AspNet.SignalR.TaskAsyncHelper.TaskRunners`2.<>c__DisplayClass3_0.<RunTask>b__0(Task`1 t)
   InnerException: 

【问题讨论】:

  • 您是否检查了 AggregateException 上的 InnerExceptions 集合?这将提供更多细节。
  • 我将异常详细信息添加到问题@sthotakura
  • 在 Connection.Start() 结束时删除 .Wait() 使程序在启动时没有错误,但是在尝试调用 Hub.Invoke() 时它说 System.InvalidOperationException, Data无法发送,因为连接处于断开状态。在发送任何数据之前调用开始
  • 您找到解决方案了吗?
  • 就我而言,在 signalR 桌面应用程序的 client 端,connection.CreateHubProxy("myHub") 方法的参数需要您在服务器端定义的 exact 集线器名称,即继承自 Hub 类。我有一个错字,修复它并工作。

标签: c# .net wpf signalr


【解决方案1】:

我遇到了同样的错误,这是因为 URL 错误。

  1. 我使用 API URL 代替了 SignalR 集线器启动的主项目 URL。
  2. 我使用的是 https 而不是 http。

这意味着,这个错误是一个通用错误,并没有提供很多细节。 请再次查看您的代码和最近的更改。

【讨论】:

  • 我很欣赏这个答案,但这篇文章已经有几年了,所以很遗憾我没有这个项目了
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-10-05
  • 1970-01-01
  • 2011-07-05
  • 1970-01-01
  • 2018-05-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多