我正在尝试在.NET Core 3.0控制台应用程序中托管Signalr集线器。我编写的代码如下。运行时,出现“ GetStreamItemType没有实现”异常。
static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) => WebHost.CreateDefaultBuilder(args).UseStartup<Startup>().Build();
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddSignalR();
}
public void Configure(IApplicationBuilder app, Microsoft.Extensions.Hosting.IHostEnvironment env)
{
app.UseSignalR(routes =>
{
routes.MapHub<Connector>("/connector");
});
}
}
连接器是我从Microsoft.AspNetCore.SignalR.Hub派生的集线器类,当应用程序启动时,出现以下异常,无法弄清原因。
System.TypeLoadException
HResult=0x80131522
Message=Method 'GetStreamItemType' in type 'Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher`1' from assembly 'Microsoft.AspNetCore.SignalR.Core, Version=1.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' does not have an implementation.
Source=Microsoft.AspNetCore.SignalR.Core
StackTrace:
at Microsoft.Extensions.DependencyInjection.SignalRDependencyInjectionExtensions.AddSignalRCore(IServiceCollection services) in /_/src/Microsoft.AspNetCore.SignalR.Core/SignalRDependencyInjectionExtensions.cs:line 36
答案 0 :(得分:0)
在寻找原因并试图了解GetStreamItemType异常时,我放弃了。最后,我创建了一个空白的.NET Core Web App,并将我的代码从控制台应用程序转移到了这个新应用程序中。
答案 1 :(得分:0)
引发此错误时,请确保您使用相同版本的Microsoft.AspNetCore.SignalR
和Microsoft.AspNetCore.SignalR.Client