无论我尝试什么,Signalr Core for ASP.net Core 2.0均无法正常工作 [英] Signalr Core for ASP.net core 2.0 not working no matter what i try

查看:313
本文介绍了无论我尝试什么,Signalr Core for ASP.net Core 2.0均无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图观看Microsoft的视频,其中包括Mikael Mengistu,Jon Galloway,Maria Naggaga.

https://channel9 .msdn.com/Shows/Code-Conversations/SignalR-Core-with-Mikael-Mengistu

0. 这是我的机器的外观. dotnet-版本2.0.0-preview2-006497 运行时Microsoft .NET Core共享框架主机版本:2.0.0-preview2-25407-01 具有Docker支持的Visual Studio 2017 15.3 MVC Web项目

这是我尝试的代码存储库. github.com/zhimaqiao1/SRcoreWorking 信号发出者客户端,我必须进行自我编辑才能至少完成一半工作.

  1. 以Vanilla MVC模板开头 以netcoreapp2.0为目标 和PackageReference Microsoft.AspNetCore.All"Version =" 2.0.0-preview2-final"

  2. 试图添加Signalr核心nuget包 来自dotnet.myget.org/F/aspnetcore-ci-dev/api/v3/index.json (这是视频中看到的nuget回购.) Microsoft.AspNetCore.SignalR版本= 1.0.0-alpha1-26462

  3. visual studio中的nuget UI警告我,它必须将某些内容升级到 2.1.0-Preview1-26462

....而没有添加一行代码,我只是f5并获得了运行时错误(不是构建错误)

在线

  public static IWebHost BuildWebHost(string[] args) =>
    WebHost.CreateDefaultBuilder(args)
        .UseStartup<Startup>()
        .Build();

the error is 

    System.MissingMethodException occurred HResult=0x80131513
    Message=Method not found: 
    System.IDisposable.Microsoft.Extensions.Options.IOptionsMonitor`1.OnChange(System.Action`1<!0>)'
    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)

  1. 我从理论上猜测,某种来自signalr的扩展方法被应用于aspnet core 2.0中的某个东西,并不是在寻找那不存在的东西.因此,我仅添加了一个信号包. Microsoft.AspNetCore.SignalR.Http版本= 1.0.0-alpha1-26462

当我按f5键时,我得到了另一个错误! (woohoo取得了进步)

   System.MissingMethodException occurred
  HResult=0x80131513
  Message=Method not found: 'System.Collections.Generic.Dictionary`2<System.String,System.Object> Microsoft.Extensions.Configuration.IConfigurationBuilder.get_Properties()'.
  Source=<Cannot evaluate the exception source>
  StackTrace:
<Cannot evaluate the exception stack trace>

5

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<System.String,System.Object> Microsoft.Extensions.Configuration.IConfigurationBuilder.get_Properties()'.

6.

我回想起我在视频中从回购中添加了第一个Signalr程序包 dotnet.myget.org/F/aspnetcore-ci-dev/api/v3/index.json

它想从我的PackageReference Microsoft.AspNetCore.All"中升级某些功能.Version ="2.0.0-preview2-final" 到2.1.0-Preview1-26462

所以我四处寻找Microsoft.AspNetCore.All 2.1.0-Preview1-26462只是为了追逐... 我在视频的同一回购中找到了它 dotnet.myget.org/F/aspnetcore-ci-dev/api/v3/index.json

我删除了所有信号包,并使用以下命令清理了我的nuget缓存 .\ nuget.exe本机全部清除

然后我按f5 (请记住,这仍然是香草mvc aspnetcore 2.0模板.我尚未添加任何代码)

我收到以下异常信息.....

发生System.IO.FileLoadException HResult = 0x80131040 消息=无法加载文件或程序集'System.Diagnostics.DiagnosticSource,版本= 4.0.2.1,区域性=中立,PublicKeyToken = cc7b13ffcd2ddd51'.找到的程序集的清单定义与程序集引用不匹配. (来自HRESULT的异常:0x80131040) 来源= 堆栈跟踪: 在Microsoft.AspNetCore.Hosting.WebHostBuilder.BuildCommonServices(AggregateException& hostingStartupErrors) 在Microsoft.AspNetCore.Hosting.WebHostBuilder.Build() 在D:\ org \ projects \ fogbridge3 \ ActorModelDojo \ src \ Solution2 \ WebApplication1 \ Program.cs:line 21中的WebApplication1.Program.BuildWebHost(String [] args) 在D:\ org \ projects \ fogbridge3 \ ActorModelDojo \ src \ Solution2 \ WebApplication1 \ Program.cs:line 17中的WebApplication1.Program.Main(String [] args)中

  1. 我尝试了很多事情来克服这个错误,只是因为 Microsoft.AspNetCore.All"Version =" 2.1.0-preview1-26462"

我试图一个接一个地添加项目,但最终所有道路都通过依赖System.Diagnostics.DiagnosticSource的Microsoft.AspNetCore.Hosting进行. 而且它永远不会让我降级以满足运行时错误. 我试图引用下级System.Diagnostics.DiagnosticSource 4.0.2.1的另一个项目 我试图直接引用dll. C:\ Users \ gracie.nuget \ packages \ system.diagnostics.diagnosticsource下有很多版本 我看了看 C:\ Users \ gracie.nuget \ packages \ system.diagnostics.diagnosticsource \ 4.0.0 \ lib并找到以下目录 净46 网络标准1.1 网络标准1.3 Portable-net45 + win8 + wpa81

所有都掩盖了Visual Studio中的错误... 该引用无效或不受支持.

我做了一个详细的构建,并发现了以下几行

     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.

所以我手动从C:\ Users \ gracie.nuget \ packages \ system.diagnostics.diagnosticsource \ 4.0.0 \ lib \ netstandard1.3复制了它 到C:\ Users \ gracie.nuget \ packages \ microsoft.aspnetcore.hosting \ 2.1.0-preview1-26462 \ lib \ netstandard2.0 \ 努力被忽略了.

然后我将其直接添加到csproj PackageReference Include ="Microsoft.AspNetCore.All" Version ="2.1.0-preview1-26462" PackageReference Include ="System.Diagnostics.DiagnosticSource" Version ="4.0.2.1"

我收到8条错误消息,说同样的话... 严重性代码说明项目文件行抑制状态 错误NU1605检测到的程序包降级:System.Diagnostics.DiagnosticSource从4.4.1降到4.0.2.1.直接从项目中引用该软件包以选择其他版本. 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

什么都不做.

所以我回到了零. 我只是添加了原始的 然后我剥离了尽可能多的MVC代码,但没有任何效果. 我仍然需要以下行,并且该行出错了.

   public static IWebHost BuildWebHost(string[] args) =>
    WebHost.CreateDefaultBuilder(args)
        .UseStartup<Startup>()
        .Build();

我什至回到了aspnetcore 1.1样式的详细托管代码.

当仅添加单个信号器程序包(任何软件包或所有软件包)时,

仍然像以前一样出错.

四天后……四天后!!!!!!!

我想到了一个组合,它似乎在运行时就运行了.

PackageReference Include ="Microsoft.AspNetCore.All" Version ="2.0.0-preview2-final" PackageReference Include ="Microsoft.AspNetCore.SignalR"版本="1.0.0-preview2-25794" PackageReference Include ="Microsoft.AspNetCore.SignalR.Http" Version ="1.0.0-preview2-25794"

我从一个新的仓库中获得了两个信号包(不是视频中的一个) aspnetcore-发布在myget dotnet.myget.org/F/aspnetcore-release/api/v3/index.json

这个默认的MVC网站运行得很好 但是我还没有添加任何信号器代码.

所以我配置了我的服务

public void ConfigureServices(IServiceCollection服务) {

    //services.AddMvc();
    services.AddSockets();
    //services.AddSocketsCore();
    services.AddSignalRCore( );
}

配置了我的管道

        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            app.UseStaticFiles();

            app.UseSignalR(routes =>
            {
                routes.MapHub<Chat>("chat");
            });

}

创建了我的中心

公共课聊天:中心 {

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);
}

}

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

在wwww文件夹的根目录下创建了一个名为chat.html的文件,其中摘录了以下代码....

让transportType = signalR.TransportType [getParameterByName('transport')] || signalR.TransportType.WebSockets;

let http = new signalR.HttpConnection(`http://${document.location.host}/chat`, { transport: transportType });
let connection = new signalR.HubConnection(http);

清除了nuget缓存

.\nuget.exe locals all -clear

仔细检查了包裹 PackageReference Include ="Microsoft.AspNetCore.All" Version ="2.0.0-preview2-final" PackageReference Include ="Microsoft.AspNetCore.SignalR"版本="1.0.0-preview2-25794" PackageReference Include ="Microsoft.AspNetCore.SignalR.Http" Version ="1.0.0-preview2-25794"

按下f5. 和BOOM !!! SyntaxError:JSON位置0上的意外令牌c

进一步检查 信号发送者-客户端到达第171行 ..... let negotiationPayload =产生this.httpClient.options(this.url); 并进行协商,Payload解析为类似于connectionid f35c2377-5477-413b-a861-e41c57ee0e92

的内容.

signalr-client中的下一行172 ......让leteResponseResponse = JSON.parse(negotiatePayload); 发生以下异常崩溃 无法启动连接. SyntaxError:JSON中位置1处的数字意外

所以我开始四处寻找信号发送者客户端,以变得更加宽容. 在克服了诸如TypeError:availableTransports等未定义的其他错误之后

我终于在.net端遇到了断点!!!!! 以及一些美观的控制台日志消息... WebSocket已连接至ws://localhost:55592/chat?id = f7c96a55-0266-452d-b071-3b04b7794aad signalr-client.js:575:21 (WebSockets传输)收到的数据:{"invocationId":"1","type":1,"target":"connectionmade","nonBlocking":true,"arguments":["connection made dude"]}

这是Signalr-client中已编辑的功能....

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 ? "?" : "&") + `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 => this.stopConnection(true, e);
            yield this.transport.connect(this.url);

最终我放弃了,因为随后的消息发送错误与 连接因错误而关闭:错误:Websocket已关闭,状态码:1011()

与以下代码有关.....

        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}'`);    <------ throws this error..
where..
input = "{"invocationId":"5","type":1,"target":"connectionmade","nonBlocking":true,"arguments":["connection made dude"]}    

请有人帮助!!! 我使用了错误的signalr-client吗?

我从哪里收到信号包的仓库 dotnet.myget.org/F/aspnetcore-release/api/v3/index.json PackageReference Include ="Microsoft.AspNetCore.SignalR"版本="1.0.0-preview2-25794" PackageReference Include ="Microsoft.AspNetCore.SignalR.Http" Version ="1.0.0-preview2-25794"

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

最后,我从 https://github.com/aspnet/SignalR 下载了源代码 并不能建立它. 聊天示例无法运行.

有人可以帮助我吗?我的商业伙伴告诉我转储asp.net核心和信号器,并选择Linux替代品. 我们的业务模型要求我们使用docker,因此要使用在linux中运行的asp.net核心. 我们不能将Signalr用于.NET框架.

这是我的机器的样子.

sdk ..... dotnet --version 2.0.0-preview2-006497

运行时 Microsoft .NET Core共享框架主机 版本:2.0.0-preview2-25407-01

具有Docker支持的Visual Studio 2017 15.3 MVC Web项目

解决方案

这会有所帮助: https://github.com/aspnet/SignalR/issues/690

更新dotnet cli和aspnetcore

trying to follow microsoft's video w/ Mikael Mengistu, Jon Galloway, Maria Naggaga.

https://channel9.msdn.com/Shows/Code-Conversations/Introduction-to-SignalR-Core-with-Mikael-Mengistu

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

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.

  1. started with vanilla mvc template which targets netcoreapp2.0 and PackageReference Microsoft.AspNetCore.All" Version="2.0.0-preview2-final"

  2. 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

  3. The nuget UI in visual studio warns me that it has to upgrade some things to 2.1.0-Preview1-26462

.... without adding a line of code i just f5 and get a runtime error ( not a build error )

at the line

  public static IWebHost BuildWebHost(string[] args) =>
    WebHost.CreateDefaultBuilder(args)
        .UseStartup<Startup>()
        .Build();

the error is 

    System.MissingMethodException occurred HResult=0x80131513
    Message=Method not found: 
    System.IDisposable.Microsoft.Extensions.Options.IOptionsMonitor`1.OnChange(System.Action`1<!0>)'
    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)

  1. 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

when i press f5 i get a different error!! ( woohoo making progress )

   System.MissingMethodException occurred
  HResult=0x80131513
  Message=Method not found: 'System.Collections.Generic.Dictionary`2<System.String,System.Object> Microsoft.Extensions.Configuration.IConfigurationBuilder.get_Properties()'.
  Source=<Cannot evaluate the exception source>
  StackTrace:
<Cannot evaluate the exception stack trace>

5

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<System.String,System.Object> Microsoft.Extensions.Configuration.IConfigurationBuilder.get_Properties()'.

6.

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

it wanted to upgrade some things from my PackageReference Microsoft.AspNetCore.All" Version="2.0.0-preview2-final" to 2.1.0-Preview1-26462

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

I removed all the signalr packages and cleaned out my nuget cache with .\nuget.exe locals all -clear

then i pressed f5 ( remember this is still vanilla mvc aspnetcore 2.0 template. no code has been added by me yet )

I get the following exception.....

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& 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

  1. I tried so many things to get past this error just coming from Microsoft.AspNetCore.All" Version="2.1.0-preview1-26462"

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

all yeilded the error from visual studio... the reference is invalid or not supported.

i did a verbose build and spotted the following lines

     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.

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.

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"

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

NOTHING WORKED.

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.

   public static IWebHost BuildWebHost(string[] args) =>
    WebHost.CreateDefaultBuilder(args)
        .UseStartup<Startup>()
        .Build();

I even went back to aspnetcore 1.1 style verbose hosting code.

still errored as before when adding just a single signalr package ( ANY PACKAGE or ALL THE PACKAGES ).

AFTER FOUR LONG DAYS... FOUR DAYS!!!!!!!

I came up on a combination that built and seemed to run at runtime.

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"

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

This default MVC website ran perfectly But i had yet to add any signalr code yet.

so i configured my services

public void ConfigureServices(IServiceCollection services) {

    //services.AddMvc();
    services.AddSockets();
    //services.AddSocketsCore();
    services.AddSignalRCore( );
}

configured my pipeline

        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            app.UseStaticFiles();

            app.UseSignalR(routes =>
            {
                routes.MapHub<Chat>("chat");
            });

}

created my hub

public class Chat : Hub {

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);
}

}

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

created a file called chat.html at the root of wwww folder with the following excerpt of code ....

let transportType = signalR.TransportType[getParameterByName('transport')] || signalR.TransportType.WebSockets;

let http = new signalR.HttpConnection(`http://${document.location.host}/chat`, { transport: transportType });
let connection = new signalR.HubConnection(http);

cleared the nuget cache

.\nuget.exe locals all -clear

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"

the pressed f5. and BOOM!!!! SyntaxError: Unexpected token c in JSON at position 0

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

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

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

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"]}

here is the edited functionality in the signalr-client....

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 ? "?" : "&") + `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 => this.stopConnection(true, e);
            yield this.transport.connect(this.url);

eventually though i gave up because subsequent message sending errors out with Connection closed with error: Error: Websocket closed with status code: 1011 ()

something to do with the following 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}'`);    <------ throws this error..
where..
input = "{"invocationId":"5","type":1,"target":"connectionmade","nonBlocking":true,"arguments":["connection made dude"]}    

PLEASE SOMEBODY HELP!!! Am i using the wrong signalr-client???

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"

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

Finally i downloaded the source from https://github.com/aspnet/SignalR and couldnt build it. the chat sample wouldnt run.

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.

here is what my machine looks like.

sdk ..... 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

解决方案

This helps a bit: https://github.com/aspnet/SignalR/issues/690

Update dotnet cli and aspnetcore

这篇关于无论我尝试什么,Signalr Core for ASP.net Core 2.0均无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆