An unexpected error occurred on a send. TLS1.1 connection Error - vb.net

We have some old VB code on a server which is compiled and is making a web service call. The provider recently updated from TLS1.1 to TLS1.2 and that's when the code stopped working and we started getting the error message
Underlying connection was closed: an unexpected error occurred on a send
I am not very familiar with VB. Are there any changes we can make on the Windows Server so that the compiled code makes a connection via TLS1.2?
It took some time, but I've added the stack trace. I've edited it a bit for privacy:
Here is the error message:
The underlying connection was closed: An unexpected error occurred on a send.
Trace:
at System.Web.Services.Protocols.WebClientProtocol.GetWebResponse(WebRequest request)
at System.Web.Services.Protocols.HttpWebClientProtocol.GetWebResponse(WebRequest request)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at (...............).BeginSession(String Profile) in C:\Users...\Desktop.............................vb:line 146
at (................)RetrieveData(Int32 queueNumber) in C:\Users(..................................).vb:line 475
at (.................) in C:\Users(...................................)vb:line 121
Here's a part of the code where a webservice connection is made (line 146 in the stack above):
<System.Web.Services.Protocols.SoapDocumentMethodAttribute("......BeginSession", RequestNamespace:="........com", ResponseNamespace:=".............com", Use:=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle:=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)> _
Public Function BeginSession(ByVal Profile As String) As String
Dim results() As Object = Me.Invoke("BeginSession", New Object() {Profile})
Return CType(results(0), String)
End Function

Add this just before the request:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
ServicePointManager.Expect100Continue = True
I think it should work then.
Worked for me, when I had an error, though a bit different one.

My issue was resolved.The steps I took was to upgrade the project by opening it in the latest version of Visual Studio (2017). I had a few errors upgrading mostly related to the solution file being read-only. I then changed the target framework of the project to 4.6.1.
After doing these changes and rebuilding the solution, the app seems to be working.

Related

Example of a .Net6 Blazor WebAssembly application with authentication using local Sql Db?

I'm trying to add authentication (with registration, password reset etc) to a .Net6 Blazor WebAssembly project. When creating the project include authentication for individual accounts (to local sql db), configure for HTTPS, Asp.Net Core hosted and Progressive Web Application. This is done in VS 2022.
The problem I'm facing is that each project I've created so far continues to crash as soon as I try to register or login.
similar to this thread: Blazor WebAssembly Hosted Proxy crash on successful authentication
I also looked at the link to https://github.com/dotnet/aspnetcore/issues/26635 but the issue was resolved. I'm currently running Chrome Version 99.0.4844.82 (Official Build) (64-bit).
I tried removing the autocomplete attribute on the server side cshtml pages but the project still random crashes.
Has anyone successfully implemented authentication (using local Sql) in a webAssebly project with .Net6?
I also tried to run the samples from the .NetCore git repo and the apps continue to crash.
This is the server console output:
fail: Microsoft.WebAssembly.Diagnostics.DevToolsProxy[0] DevToolsProxy::Run: Exception System.AggregateException: One or more errors occurred. (The remote party closed the WebSocket connection without completing the close handshake.) ---> System.Net.WebSockets.WebSocketException (0x80004005): The remote party closed the WebSocket connection without completing the close handshake. ---> System.Net.Sockets.SocketException (995): The I/O operation has been aborted because of either a thread exit or an application request. at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal.SocketAwaitableEventArgs.g__ThrowSocketException|5_0(SocketError e) at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal.SocketAwaitableEventArgs.GetResult(Int16 token) at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal.SocketConnection.DoReceive() at System.IO.Pipelines.Pipe.GetReadResult(ReadResult& result) at System.IO.Pipelines.Pipe.GetReadAsyncResult() at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Http1UpgradeMessageBody.ReadAsyncInternalAwaited(ValueTask1 readTask, CancellationToken cancellationToken) at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder1.StateMachineBox1.System.Threading.Tasks.Sources.IValueTaskSource<TResult>.GetResult(Int16 token) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpRequestStream.ReadAsyncInternal(Memory1 destination, CancellationToken cancellationToken) at System.Net.WebSockets.ManagedWebSocket.EnsureBufferContainsAsync(Int32 minimumRequiredBytes, CancellationToken cancellationToken, Boolean throwOnPrematureClosure) at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder1.StateMachineBox1.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token) at System.Net.WebSockets.ManagedWebSocket.ReceiveAsyncPrivate[TResult](Memory1 payloadBuffer, CancellationToken cancellationToken) at System.Net.WebSockets.ManagedWebSocket.ReceiveAsyncPrivate[TResult](Memory1 payloadBuffer, CancellationToken cancellationToken) at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder1.StateMachineBox1.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token) at System.Threading.Tasks.ValueTask`1.ValueTaskSourceAsTask.<>c.<.cctor>b__4_0(Object state) --- End of stack trace from previous location --- at Microsoft.WebAssembly.Diagnostics.DevToolsProxy.ReadOne(WebSocket socket, CancellationToken token) --- End of inner exception stack trace --- at Microsoft.WebAssembly.Diagnostics.DevToolsProxy.Run(Uri browserUri, WebSocket ideSocket)
This is the VS output screen details:
Exception thrown: 'System.Net.Sockets.SocketException' in Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.dll
Exception thrown: 'System.Net.Sockets.SocketException' in Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.dll
The program '' has exited with code 4294967295 (0xffffffff).
Exception thrown: 'Microsoft.AspNetCore.Connections.ConnectionResetException' in System.Private.CoreLib.dll
Exception thrown: '' in Unknown Module.
The thread 0x1 has exited with code 0 (0x0).
The program 'service-worker.js' has exited with code 4294967295 (0xffffffff).
The program '[25288] Chatter.Server.exe' has exited with code 4294967295 (0xffffffff).
The thread 0x0 has exited with code 0 (0x0).
The program 'localhost:7151' has exited with code 4294967295 (0xffffffff).
Any advise will be greatly appreciated.
Thanx
Riaan
fail: Microsoft.WebAssembly.Diagnostics.DevToolsProxy[0]
DevToolsProxy::Run: Exception System.AggregateException: One or more
errors occurred. (The remote party closed the WebSocket connection
without completing the close handshake.)
To the above error, as far as I know, after update to VS 2022 17.1, it will show the websocket error. And, if check the console output, you will find the above error.
To solve the above error, you can try to use the VS 2022 17.2.0 Preview 2.0 version, this issue has been fixed in this version. Or you can try to install the earlier VS 2022 version, refer this link. I also check it using VS 2022 17.0.4 version, it doesn't have this error, you can try to use this version.
To the Local SQL Server error, I guess you are meeting the following error, right?
To solve the above error, you can use the following migration commands to generate the DataBase first (Or you can use the existing database), then the above error will disappear when you run the application.
add-migration generateDatabase
Update-Database
More detail information about migration, see Migrations Overview.

Restsharp: Returns 0 content with error "unable to read data from the transport connection"

Background: Console app built in .Net 4.6.2
Dll: Restsharp 106.15.0.0
Mono: Mono JIT compiler version 6.12.0.122
API Endpoint: http server (not https)
At first I thought I was going mad as all was working okay on windows but when I run my console app on Debian (v9), it will constantly fail with the error: unable to read data from the transport connection. I've narrowed it down to restsharp and not a api/server issue.
When I run a debugger in parallel (HTTP Debugger) I can see the request go out from my console app on Debian and I can also see the endpoint return a result with content! This content does not come into restsharp and so restsharp gives me a content-length of 0 and an error message of:
unable to read data from the transport connection: An existing connection was forcibly closed by the remote host
Any ideas please?
Code to trigger restsharp:
Dim myUri As New Uri(url)
Dim client = New RestSharp.RestClient(myUri)
Dim request = New RestRequest With {.Method = Method.GET}
request.AddHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9")
request.AddHeader("Connection", "keep-alive")
Dim response As RestResponse = client.Execute(request)
Dim strResponse as String = response.Content)
(I've also tried without sending the headers - makes no difference, same error message)
Thanks

SSRS 403 forbidden from .NET application

We have a .NET application that is already working in a number of development and production environments. One part opens SSRS reports, one new server is giving me this error when it tries to run. I have double checked the installation of our application and done a bunch of troubleshooting including reinstalling SSRS. Any suggestions on how to troubleshoot further?
System.Web.HttpUnhandledException (0x80004005): Exception of type
'System.Web.HttpUnhandledException' was thrown. --->
System.Net.WebException: The request failed with HTTP status 403:
Forbidden.

WP7 error: "The remote server returned an error: NotFound."

I have this code that it used to work, but at some specific time it stopped to work and returned the error "The remote server returned an error: NotFound."
WebClient deliciousWebClient = new WebClient();
deliciousWebClient.Credentials = Credentials;
deliciousWebClient.DownloadStringAsync(new Uri("https://api.del.icio.us/v1/tags/get"));
deliciousWebClient.DownloadStringCompleted += (s, ee) =>
{
if (ee.Error == null)
{
…
Any suggestion on this error?
In this code, the error is pointing to delicious endpoit, but the same error is happening with some other services...
The NotFound error is a classic 404 error, so it's possible that the API endpoint is down or that it changed on you.
I'd start by using Fiddler2 to make the requests manually. That'll help you figure out whether the issue is in your code somewhere or on the API side.
It's hard to get Fiddler working with the WP7 emulator, as you noted below. One trick I've used in the past when I got really desperate was to write a quick console app that used the same code that my Windows Phone app was executing. Then I was able to successfully intercept the traffic. It turned out that my request being properly formatted.

Silverlight SecurityException

I'm POSTing data to a server and successfully execute BeginGetRequestStream, then EndGetRequestStream, write my POST data to the fill the RequestStream, and call BeginGetResponse.
BeginGetResponse successfully returns and I then call:
Dim response As HttpWebResponse = CType(MyHttpRequest.EndGetResponse(asynchronousResult), HttpWebResponse)
This line throws the folloing SecurityException Error:
{System.Security.SecurityException ---> System.Security.SecurityException: Security error.
at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
at System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClass5.b__4(Object sendState)
at System.Net.Browser.AsyncHelper.<>c__DisplayClass2.b__0(Object sendState)
--- End of inner exception stack trace ---
at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
at System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at EtsyV2NetSL.WebQuery.POST_ResponseCallback(IAsyncResult asynchronousResult)}
So my first thought was that I was being blocked by the server with their clientaccesspolicy.xml or crossdomain.xml. I've fired up Fiddler and saw the following:
GET http://openapi.etsy.com/clientaccesspolicy.xml > 596 (text/xml)
GET http://openapi.etsy.com/crossdomain.xml > 200 OK (application/xml)
So I checked their crossdomain.xml and the settings appear ok:
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-access-from domain="*"/>
</cross-domain-policy>
I've hit a dead end in trying to solve this problem. I'm running the test app on my dev machine from VS.
Does anyone have any ideas as to why Silverlight would be throwing this error?
Thanks
It seems like it's a client access policy issue, check this:
http://forums.silverlight.net/forums/p/26566/90867.aspx
It worked for me.
I dealt with a very similar problem today - however instead of an HTTP POST, I was attempting to do a WCF service call.
Here is the comment I placed in my code - please let me know if its not clear enough to be helpful.
// NB: Cross-domain bug
// If you end up here with a System.Security.SecurityException "Security error."
// Check that you're not trying to cross zones when making a service call
// (eg: Accessing Trigger Driver TimeSource service on http://IASWEB01/ when accessing the site via usertest.local
// or any other URI with dots in it - yes it seems crazy)
This seems to be some security 'feature'. With the WCF call I got this exception even before the Silverlight client attempted to fetch the clientaccesspolicy.xml from the target host. Very annoying issue without a real solution in sight!