ASP.net core 2.0 的 Signalr Core 无论我尝试什么都不工作

Signalr Core for ASP.net core 2.0 not working no matter what i try

尝试关注微软与 Mikael Mengistu、Jon Galloway、Maria Naggaga 的视频。

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

0。 这是我的机器的样子。 dotnet --version 2.0.0-preview2-006497 运行time Microsoft .NET Core 共享框架主机版本:2.0.0-preview2-25407-01 Visual Studio 2017 15.3 MVC Web 项目 Docker 支持

这是我尝试的代码库。 github.com/zhimaqiao1/SRcoreWorking signalr-client 我必须自己编辑才能让某些东西至少工作一半。

  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 中的某些扩展方法并不是在寻找不存在的东西。所以我添加了另一个 signalr 包只是为了它。 Microsoft.AspNetCore.SignalR.Http 版本=1.0.0-alpha1-26462

当我按 F5 时,我得到了一个不同的错误!! (呜呜进步了)

   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.

我记得我在视频中从回购中添加了第一个信号器包 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 locals all -clear

然后我按了f5 (记住这仍然是 vanilla mvc aspnetcore 2.0 模板。我还没有添加任何代码)

我得到以下异常......

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

  1. 我尝试了很多方法来解决这个错误 Microsoft.AspNetCore.All" 版本="2.1.0-preview1-26462"

我试图一个一个地添加项目,但最终条条大路通Microsoft.AspNetCore.Hosting,这取决于System.Diagnostics.DiagnosticSource 而且它永远不会让我降级以满足 运行 时间错误。 我试图引用另一个下层 System.Diagnostics.DiagnosticSource 4.0.2.1 的项目 我试图直接引用 dll。 C:\Users\gracie.nuget\packages\system.diagnostics.diagnosticsource下有很多版本 我看了看 C:\Users\gracie.nuget\packages\system.diagnostics.diagnosticsource.0.0\lib 找到如下目录 网络46 netstandard1.1 netstandard1.3 便携-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.1.0-preview1-26462\lib\netstandard2.0".
             Considered "C:\Users\gracie\.nuget\packages\microsoft.aspnetcore.hosting.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.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.1.0-preview1-26462\lib\netstandard2.0\System.Diagnostics.DiagnosticSource.exe", but it didn't exist.

所以我手动从 C:\Users\gracie.nuget\packages\system.diagnostics.diagnosticsource.0.0\lib\netstandard1.3 复制了它 到 C:\Users\gracie.nuget\packages\microsoft.aspnetcore.hosting.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。直接从项目引用包到 select 不同的版本。 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" Version="1.0.0-preview2-25794" PackageReference Include="Microsoft.AspNetCore.SignalR.Http" Version="1.0.0-preview2-25794"

我从一个新的 repo 中获得了两个信号器包(不是视频中的那个) myget 上的 aspnetcore 发布 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 class 聊天:中心 {

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 的文件....

让 t运行sportType = 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" Version="1.0.0-preview2-25794" PackageReference Include="Microsoft.AspNetCore.SignalR.Http" Version="1.0.0-preview2-25794"

按下的 f5。 和繁荣! SyntaxError:JSON 中位置 0

中的意外标记 c

经进一步检查 signalr-client 到达第 171 行 .....let negotiatePayload = yield this.httpClient.options(this.url); negotiatePayload 解析为看起来像 connectionid f35c2377-5477-413b-a861-e41c57ee0e92

的内容

signalr-client 中的下一行 172 ......让negotiateResponse = JSON.parse(negotiatePayload); 崩溃并出现以下异常 无法启动连接。语法错误:JSON 中位置 1

中的意外数字

所以我开始考虑改用更宽松的 signalr-client。 在克服了更多错误之后,例如 TypeError: availableT运行sports is undefined

我终于在 .net 端遇到断点了!!!!!!! 和一些好看的控制台日志消息... WebSocket 连接到 ws://localhost:55592/chat?id=f7c96a55-0266-452d-b071-3b04b7794aad signalr-client.js:575:21 (WebSockets t运行sport) 收到的数据:{"invocationId":"1","type":1,"target":"connectionmade","nonBlocking":是的,"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" 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

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

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

这是我的机器的样子。

SDK..... dotnet --version 2.0.0-preview2-006497

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

Visual Studio 2017 15.3 MVC Web 项目 Docker 支持

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

更新 dotnet cli 和 aspnetcore

只是为了澄清,因为电子邮件是我在 4 天内混合和匹配来自不同来源的包的经验的庞大帐户...

问题是在运行时开始的,没有写一行代码只是 f5 visual studio 2017 15.3

中的默认 mvc 模板
  public static IWebHost BuildWebHost(string[] args) =>
    WebHost.CreateDefaultBuilder(args)
        .UseStartup<Startup>()
        .Build();

根据我使用的包组合,有各种不同的包

System.MissingMethodException occurred HResult=0x80131513
Message=Method not found: 'System.IDisposable.Microsoft.Extensions.Options.IOptionsMonitor1.OnChange(System.Action1)'. Source= StackTrace: at 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)

System.MissingMethodException occurred HResult=0x80131513
Message=Method not found: 'System.Collections.Generic.Dictionary`2 Microsoft.Extensions.Configuration.IConfigurationBuilder.get_Properties()'.

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

同样,这没有写一行信号器代码!!!

一旦我获得了 signalr 与 asp.net 核心的包组合,所有这些都通过了,没有任何运行时异常...然后我添加了 signalr 代码。

让我通过普通 vanilla mvc 模板代码的运行时错误的组合是

aspnetcore-release (prerelease) https://dotnet.myget.org/F/aspnetcore-release/api/v3/index.json for PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.0.0-preview2-25794" PackageReference Include="Microsoft.AspNetCore.SignalR.Http" Version="1.0.0-preview2-25794"

nuget.org (prerelease) ​https://api.nuget.org/v3/index.json PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0-preview2-final"

但后来我发现 none 的客户工作了

npm install signalr-client --registry dotnet.myget.org/F/aspnetcore-ci-dev/npm --save-dev

或客户在

提及

github.com/aspnet/SignalR

那是我不得不自己编辑客户端以强制它至少在

处遇到断点的时候
    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);
}
thanks that works but now docker image deployment breaks :(

are there any docs out there that can guide me to create my own aspnetcore 2.1 linux docker image  to deploy to?

-------------------------------------------------------------------
You may only use the Microsoft .NET Core Debugger (vsdbg) with
Visual Studio Code, Visual Studio or Visual Studio for Mac software
to help you develop and test your applications.
-------------------------------------------------------------------
realpath(): Invalid argument
realpath(): Invalid argument
realpath(): Invalid argument
It was not possible to find any compatible framework version
The specified framework 'Microsoft.NETCore.App', version '2.0.0' was not found.
- Check application dependencies and target a framework version installed at:
/
- Alternatively, install the framework version '2.0.0'.
The target process exited without raising a CoreCLR started event. Ensure that the target process is configured to use .NET Core. This may be expected if the target process did not run on .NET Core.
The program '[52] dotnet' has exited with code 131 (0x83).
The program '' has exited with code 131 (0x83).