Failed to deploy NuGet package

You might see one or more of the following error messages when trying to deploy a NuGet package:

Failed to deploy NuGet package '_IronPdf.Native.Chrome.Windows(version)'
System.Net.WebException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send.
System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host

Possible Cause

The most common cause of these errors is related to outdated TLS protocols. As of June 15, 2020, NuGet has removed support for TLS 1.0 and 1.1, and now enforces TLS 1.2. If TLS 1.2 is not enabled on your system, NuGet commands may fail.

Switching from HTTP to HTTPS won't resolve the issue if TLS 1.2 is not enabled, as NuGet now requires secure connections.

Solutions

  1. Install Visual C++ Runtimes: Ensure that the Visual C++ Redistributable for Visual Studio is installed on your system. Missing runtimes can cause issues with certain packages, including IronPDF.

  2. Update Visual Studio: Make sure you are using a recent, up-to-date version of Visual Studio. Visual Studio 2015 or higher is required to properly support modern TLS protocols.

    1. In Visual Studio, go to:
      • Tools > Extensions and Updates > Updates > Visual Studio Gallery
      • Update the NuGet Package Manager to the latest version.
  3. Enable Strong Cryptography in .NET: If the above steps do not resolve the issue, you may need to enable strong cryptography in .NET. This can be done by modifying the registry.

    1. Create a .reg file with the following content:

      [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319]
      "SchUseStrongCrypto"=dword:00000001
      
      [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\v4.0.30319]
      "SchUseStrongCrypto"=dword:00000001
    2. Run the .reg file to update the registry settings. This enables strong cryptography in .NET, allowing TLS 1.2 connections.

No reboot is required. After applying these changes, try running your NuGet command again.

For more details, refer to this Stack Overflow post: NuGet fails: The underlying connection was closed: An unexpected error occurred.

Reach out to us by submitting Engineering Request should you need further assistance.