I’m experimenting with the Microsoft HTTP server sample in release 4.2 on a Cobra 1 board. I’ve created my own self-signed certificate using openSSL, installed it as a resource, but can’t get to work.
The problem is that the application throws an exception, displays the exception in the Debug window, and then locks up. I have a try-catch around the offending method, but it never gets caught, so it’s hard to determine what is wrong.
The code is almost straight from the sample project:
IP address is set
Running Web Server
Type this IP address to access the webpage: 192.168.1.7
The thread '<No Name>' (0x1) has exited with code 0 (0x0).
#### Exception System.Net.Sockets.SocketException - CLR_E_FAIL (5) ####
#### Message:
#### Microsoft.SPOT.Net.Security.SslNative::SecureServerInit [IP: 0000] ####
#### Microsoft.SPOT.Net.Security.SslStream::Authenticate [IP: 0037] ####
#### Microsoft.SPOT.Net.Security.SslStream::AuthenticateAsServer [IP: 000d] ####
#### Microsoft.SPOT.Net.Security.SslStream::AuthenticateAsServer [IP: 0008] ####
#### System.Net.HttpListener::AcceptThreadFunc [IP: 0072] ####
#### SocketException ErrorCode = -1
#### SocketException ErrorCode = -1
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in Microsoft.SPOT.Net.Security.dll
#### SocketException ErrorCode = -1
#### SocketException ErrorCode = -1
#### SocketException ErrorCode = -1
#### SocketException ErrorCode = -1
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.Net.Security.dll
#### SocketException ErrorCode = -1
#### SocketException ErrorCode = -1
The program '[2] Micro Framework application: Managed' has exited with code 0 (0x0).
Any ideas why the exception is not being caught, and what may be causing it?
Thanks.
Thanks @ Andre. There was a problem with my certificate… I forgot to add a private key. The code works now, but I would like to know why the exception was not propagated to my try-catch. If the exception was caught in the HttpListener, then why did it hang aftwerwards? It seems like a bug.
I modified the code as shown below to include references to exception classes in the catch statements.
I set break points at the lock (m_responseQueue) statement, and within each catch block.
I loaded the “bad” certificate into the listener, and accessed the device from my browser.
I got the same exception messages as before, but none of the breakpoints were hit.
This tells me that the exception being thrown by the SslStream.AuthenticateAsServer method is being caught and handled within the GetContext method, and as a result the method never returns to my program.
Wouldn’t it better better practice to either:
[ul]catch the exception, and return a null HttpListenerContext, or
allow the exception to bubble up to my code[/ul]
Yes, the listener keeps running, but as long as the browser continues to request a secure page, nothing is returned. My code doesn’t know anything is wrong, and the user never sees a page or error message or anything!
In my opinion, if something occurs that causes an exception, and it can’t be fixed, then GetContext should allow the exception to bubble up to the calling code.