【问题标题】:Signalr Core for ASP.net core 2.0 not working no matter what i tryASP.net core 2.0 的 Signalr Core 无法正常工作,无论我尝试什么
【发布时间】:2018-01-11 19:32:03
【问题描述】:

试图关注微软与 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 运行时 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. 尝试添加信号器核心 nuget 包 来自 dotnet.myget.org/F/aspnetcore-ci-dev/api/v3/index.json (这是视频中看到的 nuget repo。) 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. 我从理论上猜测,某些扩展方法来自信号器并应用于 aspnet 核心 2.0 中的某些东西,并不是在寻找不存在的东西。所以我添加了另一个信号包只是为了它。 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.

我记得当我从视频中的 repo 添加第一个 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 locals all -clear

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

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

发生 System.IO.FileLoadException H结果=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"

我试图一个一个地添加项目,但最终所有的道路都通过 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\4.0.0\lib 并找到以下目录 网46 网络标准1.1 网络标准1.3 便携-net45+win8+wpa81

所有人都承认了来自视觉工作室的错误...... 引用无效或不受支持。

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

     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 包括="Microsoft.AspNetCore.All" 版本="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。诊断源 (>= 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 风格的详细托管代码。

在添加单个信号包( ANY PACKAGE 或 ALL THE PACKAGES )时仍然像以前一样出错。

经过漫长的四天……四天!!!!!!!

我想出了一个可以在运行时构建并且似乎可以运行的组合。

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

我从一个新的 repo 获得了两个信号包(不是视频中的那个) aspnetcore-release 在 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" 版本="2.0.0-preview2-final" PackageReference 包括="Microsoft.AspNetCore.SignalR" 版本="1.0.0-preview2-25794" PackageReference Include="Microsoft.AspNetCore.SignalR.Http" Version="1.0.0-preview2-25794"

按下的 f5。 和繁荣!!!! SyntaxError:JSON 中位置 0 处的意外标记 c

经进一步检查 信号器客户端进入第 171 行 .....让negotiatePayload = yield this.httpClient.options(this.url); 并且negotiatePayload 解析为类似于connectionid f35c2377-5477-413b-a861-e41c57ee0e92

signalr-client 中的下一行 172 ......让negotiateResponse = JSON.parse(negotiatePayload); 崩溃,但出现以下异常 无法启动连接。 SyntaxError: JSON 中位置 1 的意外数字

所以我开始着手更改信号器客户端以更加宽松。 在克服了一些错误后,例如 TypeError: availableTransports is undefined

我终于在 .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"]}    

请大家帮忙!!! 我是不是用错了信号器客户端???

我从那里得到信号包的 repo dotnet.myget.org/F/aspnetcore-release/api/v3/index.json PackageReference 包括="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 core 和 signalr 并使用 linux 替代品。 我们的商业模式要求我们使用 docker 和在 linux 中运行的 asp.net 核心。 我们不能将 Signalr 用于 .NET 框架。

这是我的机器的样子。

sdk ..... dotnet--版本 2.0.0-preview2-006497

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

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

【问题讨论】:

  • 它们是预发布库。你期待什么?当我看的时候——那个视频是个坏主意。旨在针对 SignalR 核心的新手的视频,告诉他们安装夜间软件包。只是自找麻烦。
  • 我能够让预览版正常工作。在我发现 javascript npm 包被重命名之前,我遇到了很多像你一样的错误。此外,您的 ASP.NET Core 版本和 javascript 版本必须完全匹配。 npm install @aspnet/signalr@1.0.0-preview1-final --save

标签: asp.net-core signalr signalr.client


【解决方案1】:

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

更新 dotnet cli 和 aspnetcore

【讨论】:

    【解决方案2】:

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

    问题在运行时开始,无需编写一行代码,只需 f5 Visual Studio 2017 15.3 中的默认 mvc 模板

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

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

    System.MissingMethodException 发生 HResult=0x80131513
    消息=未找到方法: 'System.IDisposable.Microsoft.Extensions.Options.IOptionsMonitor1.OnChange(System.Action1)'。 来源= StackTrace:在 Microsoft.Extensions.Logging.Console.ConsoleLoggerProvider..ctor(IOptionsMonitor`1 选项)在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite,ServiceProvider 提供者)

    System.MissingMethodException 发生 HResult=0x80131513
    消息=未找到方法: 'System.Collections.Generic.Dictionary`2 Microsoft.Extensions.Configuration.IConfigurationBuilder.get_Properties()'。

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

    这又是不用写一行信号器代码!!!

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

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

    aspnetcore-release(预发布) https://dotnet.myget.org/F/aspnetcore-release/api/v3/index.json 为 PackageReference Include="Microsoft.AspNetCore.SignalR" 版本="1.0.0-preview2-25794" 包参考 包括="Microsoft.AspNetCore.SignalR.Http" 版本="1.0.0-preview2-25794"

    nuget.org(预发布)​https://api.nuget.org/v3/index.json PackageReference Include="Microsoft.AspNetCore.All" 版本="2.0.0-preview2-final"

    但后来我发现的客户都没有工作

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

    【讨论】:

      【解决方案3】:
      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).
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-04-08
        • 1970-01-01
        • 2021-08-03
        • 2020-09-27
        • 2020-10-07
        • 2019-09-26
        • 2020-10-31
        • 1970-01-01
        相关资源
        最近更新 更多