首页 文章

无论我尝试什么,ASP.net核心2.0的信号器核心都无法正常工作

提问于
浏览
1

试图跟随微软的视频与Mikael Mengistu,Jon Galloway,Maria Naggaga .

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

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

这是我尝试的代码回购 . github.com/zhimaqiao1/SRcore工作信号器 - 客户端我不得不编辑自己以获得至少一半工作的东西 .

  • 以vanilla mvc模板开始,目标是netcoreapp2.0和PackageReference,Microsoft.AspNetCore.All“Version =”2.0.0-preview2-final“

  • 试图从dotnet.myget.org/F/aspnetcore-ci-dev/api/v3/index.json添加信号器核心nuget包(这是视频中看到的nuget repo . )Microsoft.AspNetCore.SignalR Version = 1.0的3.0 alpha1-26462

  • 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)
  • 我理论上猜测来自信号器的一些扩展方法应用于aspnet core 2.0中的某些东西并不是在寻找那些不存在的东西 . 所以我添加另一个信号器包只是为了它 . Microsoft.AspNetCore.SignalR.Http Version = 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>

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的第一个信号器包时,我想起了回复.netnet.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.exe locals all -clear清除了我的nuget缓存

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

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

发生System.IO.FileLoadException HResult = 0x80131040消息=无法加载文件或程序集'System.Diagnostics.DiagnosticSource,Version = 4.0.2.1,Culture = neutral,PublicKeyToken = cc7b13ffcd2ddd51' . 定位的程序集的清单定义与程序集引用不匹配 . (来自HRESULT的异常:0x80131040)Source = StackTrace:位于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:第21行,位于D:\ org \ projects \ fogbridge3 \ ActorModelDojo \ src \ Solution2中的WebApplication1.Program.Main(String [] args) \ WebApplication1 \ Program.cs:第17行

  • 我尝试了很多东西来解决这个错误,只是来自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并找到了以下目录为net46 netstandard1.1 netstandard1.3 portable-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 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”Version =“1.0.0-preview2-25794”PackageReference Include =“Microsoft.AspNetCore . SignalR.Http“Version =”1.0.0-preview2-25794“

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

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

所以我配置了我的服务

public void ConfigureServices(IServiceCollection services){

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

配置我的管道

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

            app.UseSignalR(routes =>
            {
                routes.MapHub<Chat>("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

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

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

清除了nuget缓存

.\nuget.exe locals all -clear

double检查包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 . 和BOOM !!!! SyntaxError:位于0的JSON中的意外标记c

在进一步检查时,signalr-client进入第171行..... let negotiatePayload = yield this.httpClient.options(this.url);并且negotiatePayload解析为看起来像connectionid的东西f35c2377-5477-413b-a861-e41c57ee0e92

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

所以我开始改变信号器 - 客户端变得更宽松 . 在克服了一些像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"]}

请帮助一些人!!!我使用错误的信号器 - 客户端???

我从哪里获得信号器包的repo.netget.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,因此在linux中运行asp.net核心 . 我们不能使用Signalr for .NET framework .

这是我的机器看起来的样子喜欢 .

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项目

3 回答

  • 2

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

    更新dotnet cli和aspnetcore

  • 0
    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).
    
  • 0

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

    麻烦在运行时开始,而不是在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)' . Source = StackTrace:位于Microsoft.Extensions.Exception上的System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()的Microsoft.Extensions.Logging.Console.ConsoleLoggerProvider..ctor(IOptionsMonitor1选项) . ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite) ,ServiceProvider提供程序)发生System.MissingMethodException HResult = 0x80131513消息=未找到方法:'System.Collections.Generic.Dictionary2 Microsoft.Extensions.Configuration.IConfigurationBuilder.get_Properties()' . 发生System.IO.FileLoadException HResult = 0x80131040消息=无法加载文件或程序集'System.Diagnostics.DiagnosticSource,Version = 4.0.2.1,Culture = neutral,PublicKeyToken = cc7b13ffcd2ddd51' . 定位的程序集的清单定义与程序集引用不匹配 . (来自HRESULT的异常:0x80131040)Source = StackTrace:位于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:第21行,位于D:\ org \ projects \ fogbridge3 \ ActorModelDojo \ src \ Solution2中的WebApplication1.Program.Main(String [] args) \ WebApplication1 \ Program.cs:第17行

    再次,这是没有写一行信号代码!!!

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

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

    aspnetcore-release(预发布)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(预发布)https://api.nuget.org/v3/index.json PackageReference Include =“Microsoft.AspNetCore.All”Version =“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);
    }
    

相关问题