I'm trying to add a WebSocket to existing code which handles HTTP requests. Not using IIS or ASP.NET, just C# code with an HttpListener. When the client sends the upgrade request, the server bombs:
System.Net.WebSockets.WebSocketException was unhandled by user code
ErrorCode=1229
HResult=-2147467259
Message=An error occurred when sending the WebSocket HTTP upgrade response during the AcceptWebSocketAsync operation. The HRESULT returned is '1229'
NativeErrorCode=1229
Source=System
StackTrace:
at System.Net.WebSockets.WebSocketHelpers.<AcceptWebSocketAsyncCore>d__17.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 System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at mycode.<mymethod>d__46.MoveNext()
InnerException:
Calling code:
HttpListenerContext context = listener.GetContext();
if (context.Request.IsWebSocketRequest)
{
HttpListenerWebSocketContext wsContext = await context.AcceptWebSocketAsync(null);
I find the MS documentation on the entire WebSockets namespace to be useless with no code examples. I don't know what it's trying to tell me here (other than the obvious fact that I'm not handling the exception - I want to know why there is an exception in the first place).
This is Windows 10, .NET framework 4.5. I have noticed places in the documentation which say that WebSockets only works with Windows 8 and 2012, but I assume it should work with 10 too.
Had to go to Windows Features, under IIS (even though I'm not using IIS), and turn on WebSocket Protocol. I don't know whether this being off is Win10 default or just due to the image IT installed for me.
Related
I have an exception thrown in my ASP.NET Core Web API project.
And I do get the exception name and stacktrace and everything, but the problem is that I get that as a response to the API request, but I want Visual Studio to take me immediately to the exception where and when it was thrown, like I have placed a breakpoint to it.
This is something that used to work in regular ASP.NET Core MVC projects, but for some reason it doesn't work in Web API.
Also, to clarify - I don't have any global exception handling filter or middleware, I just call app.UseDeveloperExceptionPage(); to get the detailed exception in development, this is from my HTTP request pipeline:
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseSwagger();
app.UseSwaggerUI();
}
else
{
app.UseCustomExceptionHandler();
}
// Other irrelevant middlewares...
you need to set the Visual Studio like this:
link.
Based on #XinranShen answer I also needed to update the debug settings.
I checked the setting marked below:
Created a new project for the Enterprise template, works fine in emulator (development and production), but in Web Chat, after waking it up with "hi", get the welcome card and "What is your name?" then "Sorry, it looks like something went wrong.". I have found this is due to a MissingMemberException exception at the first line of OnboardingDialog.AskForEmail where it retrieves the state:
_state = await _accessor.GetAsync(sc.Context);
One odd thing is that the AskForName method is called before this and successfully gets the (empty) state, but then doesn't actually wait for a response.
Any ideas?
Stack trace:
System.MissingMemberException: Property not set and no default provided.
at Microsoft.Bot.Builder.BotState.BotStatePropertyAccessor`1.d__7.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at EnterpriseBot.OnboardingDialog.d__8.MoveNext() in C:\dev\EnterpriseBot\EnterpriseBot\Dialogs\Onboarding\OnboardingDialog.cs:line 62
...
Thanks for any help,
David
I followed this steps to setup my own nuget server on local machine (Mac)
https://learn.microsoft.com/en-us/nuget/hosting-packages/nuget-server
I got to step 6 and then when i click "here" it gives me the following error
System.Web.HttpException
The resource cannot be found.
Description: HTTP 404.The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Details: Requested URL: /nuget/Packages
Exception stack trace:
at System.Web.StaticFileHandler.ProcessRequest (System.Web.HttpContext context) [0x00094] in /private/tmp/source-mono-2017-02/bockbuild-2017-02/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/System.Web/System.Web/StaticFileHandler.cs:77
at System.Web.DefaultHttpHandler.BeginProcessRequest (System.Web.HttpContext context, System.AsyncCallback callback, System.Object state) [0x0007f] in /private/tmp/source-mono-2017-02/bockbuild-2017-02/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/System.Web/System.Web/DefaultHttpHandler.cs:101
at System.Web.HttpApplication+<Pipeline>d__225.MoveNext () [0x008d4] in /private/tmp/source-mono-2017-02/bockbuild-2017-02/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/System.Web/System.Web/HttpApplication.cs:1335
at System.Web.HttpApplication.Tick () [0x00000] in /private/tmp/source-mono-2017-02/bockbuild-2017-02/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/System.Web/System.Web/HttpApplication.cs:927
Please help
I can see two issues in this approach.
Nuget.Server documentation mentions IIS as the web sever; IIS doesn't run on Mac OSX.
And, even if you end up using the native web server of your operating system, you will need WCF support in mono - which looks to be a work in progress.
Recently I updated the scheme from http to https in my window phone app. So far network request works fine.
However, the live tile is not working anymore.
Then I tried to debug and found that:
System.ArgumentException occurred at Microsoft.Phone.TaskModel.Interop.ApplicationHost.GetFileSystemPath(String uri)
Also:
System.Reflection.TargetInvocationException occurred Message:
A first chance exception of type
'System.Reflection.TargetInvocationException'
occurred in mscorlib.ni.dll
Additional information: Exception has been thrown by the target of an
invocation.
Finally:
at Microsoft.Phone.TaskModel.Interop.ApplicationHost.GetFileSystemPath(String uri)
at Microsoft.Phone.Shell.ShellTileData.GetLocalFilePath(Uri imageUri)
at Microsoft.Phone.Shell.UriToLocalStoreConverter.Convert(Object value, Type targetType, Object parameter, CultureInfo culture)
at Microsoft.Phone.Shell.ShellTileData.SerializeToToken(IPMTileInfo token)
at Microsoft.Phone.Shell.ShellTile.Update(ShellTileData data)
at AlarmScheduledTaskAgent.ScheduledAgentSettings.updateLiveTileUI()
I know the issue comes from the URI image for liveTile because if I change back to http liveTile is loading the image correctly. Also I tried to use another http image it doesn't crash. But if I use another https image online it crashes.
Although I didn't find anything indicating liveTile doesn't support https, anyone knows how to fix the issue? Thanks!
So I try to make a post request having no internet connection using next modified code:
WinHttpReq := CreateOleObject('WinHttp.WinHttpRequest.5.1');
WinHttpReq.Open('POST', '<your_web_server>', false);
WinHttpReq.SetRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
try
WinHttpReq.Send('data');
except
bla:= 'e';
finally
bla := 'f';
end;
Yet exception does not get catched and I get crush of my setup application with next image:
How to handle OleObject exception in Inno Setup?
Your code is incomplete, but try..except block catches all the exceptions, including those thrown by OLE objects. However, your screenshot shows the line number, where the exception was thrown, and so you were running debugger.
And debugger shows all exception messages regardless they are in a try..except block, unless you uncheck "Pause on exceptions" option in Inno Setup IDE settings:
By default is this option enabled (which I would recommend to keep), which means that all exceptions are reported as exception messages and that's what might have mislead you. If you were running your setup without debugger attached, you wouldn't see that exception message.