question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SocketTaskExtensions Class is not supported on .Net Framework 4.6.2

See original GitHub issue

FTP Server OS: Windows

FTP Server Type: Windows Server IIS

Client Computer OS: Windows

FluentFTP Version: 4.2

Framework: .NET 4.6.2

.Net 4.6.2 does not support SocketTaskExtensions so it fails to compile.

The problem is in Streams\FtpSocketStream.cs

The following method fixes.

	/// <summary>
		/// Connect to the specified host
		/// Detects timeout and throws that explicitly
		/// </summary>
		/// <param name="ipad">The ip address to connect to</param>
		/// <param name="port">The port to connect to</param>
		private async Task<bool> ConnectAsyncHelper(IPAddress ipad, int port, CancellationToken token) {

			int ctmo = this.ConnectTimeout;

#if NETSTANDARD
			try {
				using (var timeoutSrc = CancellationTokenSource.CreateLinkedTokenSource(token)) {
					timeoutSrc.CancelAfter(ctmo);
					await EnableCancellation(m_socket.ConnectAsync(ipad, port), timeoutSrc.Token, () => DisposeSocket());
				}
			}
			catch (SocketException ex) {
				if (ex.SocketErrorCode == SocketError.OperationAborted ||
					ex.SocketErrorCode == SocketError.TimedOut) {
					throw new TimeoutException("Timed out trying to connect!");
				}
				throw;
			}
#else
			 try {
#if v472
				 
				    using (var timeoutSrc = CancellationTokenSource.CreateLinkedTokenSource(token)) {
					timeoutSrc.CancelAfter(ctmo);

                    await EnableCancellation(m_socket.ConnectAsync(ipad, port), timeoutSrc.Token, () => DisposeSocket());
					}
#else
				using (var timeoutSrc = CancellationTokenSource.CreateLinkedTokenSource(token)) {
					timeoutSrc.CancelAfter(ctmo);
					var connectResult = m_socket.BeginConnect(ipad, port, null, null);
					await EnableCancellation(Task.Factory.FromAsync(connectResult, m_socket.EndConnect), timeoutSrc.Token, () => DisposeSocket());
				}
#endif
			}
			catch (SocketException ex) {
				if (ex.SocketErrorCode == SocketError.OperationAborted ||
					ex.SocketErrorCode == SocketError.TimedOut) {
					throw new TimeoutException("Timed out trying to connect!");
				}
				throw;
			}
			catch (ObjectDisposedException ex) {
				throw new TimeoutException("Timed out trying to connect!");
			}
#endif
					return m_socket.Connected;
		}

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
FanDjangocommented, Nov 21, 2022

@sandra-dcs Please see PR #1056.

Question: Do you believe a change to MoveFile(...) like yours, is an enhancement we should include?

0reactions
FanDjangocommented, Dec 1, 2022

Released as V42.1.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can not add .NET framework 4.6.2 web app reference to . ...
I have created a .NET framework 4.6.2 web application. Then I have created a .NET Standard class library. The target framework is 1.6...
Read more >
NET Standard issues on .NET Framework 4.7.1 #567
Summary Applications that target the .NET Framework 4.6.1 and use .NET Standard libraries may experience System.
Read more >
Troubleshoot blocked .NET Framework installations and ...
Troubleshoot issues you encounter that prevent installation of the .NET Framework. Consult status messages for information to resolve ...
Read more >
Troubleshoot .NET Framework targeting errors
To resolve the error, make sure that your application targets a .NET version that's compatible with the version that's targeted by the projects ......
Read more >
Visual Studio doesn't recognize .NET Framework 4.6.2 is ...
I've installed .NET Framework 4.6.2 via the web installer, and everything looked good. However, after I restarted and opened up Visual ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found