问题
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.
started with vanilla mvc template which targets netcoreapp2.0 and PackageReference Microsoft.AspNetCore.All" Version="2.0.0-preview2-final"
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
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)
- 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
- 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
回答1:
This helps a bit: https://github.com/aspnet/SignalR/issues/690
Update dotnet cli and aspnetcore
回答2:
Just for clarification because the emailing is sprawling account of my experience over 4 days of mixing and matching packages from different sources...
The trouble started at runtime without writing a line of code just f5 the default mvc template in visual studio 2017 15.3
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
were various different ones depending on the package combinations i used
System.MissingMethodException occurred HResult=0x80131513
Message=Method not found: 'System.IDisposable.Microsoft.Extensions.Options.IOptionsMonitor1.OnChange(System.Action
1)'. 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
again this is without writing a line of signalr code!!!
once i got a package combination of signalr with asp.net core all that passed without any runtime exception... i then added the signalr code.
the combination that got me passed the runtime errors of just plain vanilla mvc template code was
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"
and
nuget.org (prerelease) https://api.nuget.org/v3/index.json PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0-preview2-final"
but then none of the clients i found worked
npm install signalr-client --registry dotnet.myget.org/F/aspnetcore-ci-dev/npm --save-dev
or the client mention at
github.com/aspnet/SignalR
thats when i had to edit the client myself to force it to at least hit a breakpoint at
public override async Task OnConnectedAsync()
{
await Clients.Client(Context.ConnectionId).InvokeAsync("connectionmade", "connection made dude");
await base.OnConnectedAsync();
}
but i never succeeded in hitting my methods at
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).
来源:https://stackoverflow.com/questions/45497003/signalr-core-for-asp-net-core-2-0-not-working-no-matter-what-i-try