Skip to content
This repository has been archived by the owner on Feb 23, 2021. It is now read-only.

Owin.OwinWebSockets sample broken #81

Closed
JunTaoLuo opened this issue Dec 19, 2015 · 5 comments
Closed

Owin.OwinWebSockets sample broken #81

JunTaoLuo opened this issue Dec 19, 2015 · 5 comments

Comments

@JunTaoLuo
Copy link
Contributor

An internal error occurs when running this sample. Using diagnostics I see:

System.Collections.Generic.KeyNotFoundException: websocket.Accept
   at Microsoft.AspNet.Owin.OwinEnvironment.System.Collections.Generic.IDictionary<System.String,System.Object>.get_Item(String key)
   at SelfHostServer.Startup.<>c__DisplayClass0_0.<<Configure>b__2>d.MoveNext() in C:\gh\Entropy\samples\Owin.OwinWebSockets\Startup.cs:line 47
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNet.Owin.WebSocketAcceptAdapter.<>c__DisplayClass6_0.<<AdaptWebSockets>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNet.Diagnostics.DeveloperExceptionPageMiddleware.<Invoke>d__7.MoveNext()

Seems like we need to handle the case when the key doesn't even exist.

@muratg
Copy link

muratg commented Jan 4, 2016

@JunTaoLuo is this on CoreCLR or CLR/Mono or both?

@Tratcher any ideas?

@JunTaoLuo
Copy link
Contributor Author

I tested this on CLR previously, did not confirm on CoreCLR but I presume the same issue will occur.

@JunTaoLuo
Copy link
Contributor Author

The issue was that https://github.com/aspnet/Entropy/blob/dev/samples/Owin.OwinWebSockets/Startup.cs#L45 fails since the key websocket.Accept does not exist. Possibly, we just need to check for existence first using env.Contains or use env.TryGetValue instead of using the indexer.

@Tratcher
Copy link
Member

Tratcher commented Jan 4, 2016

I think the dictionary use to return null for missing entries but now throws. Change to TryGetValue.

@JunTaoLuo
Copy link
Contributor Author

merged to dev

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants