npgsql: Specified SSL Protocol Type is not Valid

I am using an application that is imbedded within Autodesk Revit levering their open API. I have worked inside this context for a couple years and connected to other industry DB platform without any issues.

1. I have the application that makes a call to another dll (pgRDG)

using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;

namespace RDG_Revit_2022.Testing
{
	[Transaction(TransactionMode.Manual)]
	class Test : IExternalCommand
	{
		public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
		{
			UIApplication uiapp = commandData.Application;
			Document doc = uiapp.ActiveUIDocument.Document;

			//This is the external reference call
			pg.RDG.Connection.Testing();
			return Result.Succeeded;
		}
	}
}

2. Then here is the Testing() method.

using System;
using System.Windows;
using Npgsql;

namespace pgRDG
{
	public class Connection
    {
        public static void Testing()
		{
			string ConnString = "Server=name.postgres.database.azure.com;Database=dbName;Port=5432;User Id=uid;Password=pw;Trust Server Certificate=true;Ssl Mode=Require";
			using(NpgsqlConnection conn = new NpgsqlConnection(ConnString))
			{
				try
				{
					conn.Open();
					NpgsqlCommand cmd = new NpgsqlCommand("SELECT * FROM tableName", conn);
					NpgsqlDataReader reader = cmd.ExecuteReader();
					while(reader.Read())
					{
						MessageBox.Show(reader.GetString(reader.GetOrdinal("command")));
					}
				}
				catch(Exception ex)
				{
					MessageBox.Show(ex.ToString());
				}
			}
		}
    }
}

The issue

  1. When I run this I receive the following error: image

If I run this exact same code from a desktop application it connects fine, but always produces this error within the Revit context.

I have also created a request on the Autodesk forums thinking someone there may have an idea as well. https://forums.autodesk.com/t5/revit-api-forum/revit-2022-environment-preventing-ssl-handshake-with-postgresql/td-p/10304990

Further technical details

Npgsql version: 6.0.0-preview2 PostgreSQL version: Azure version 11 Operating system: Window 10 x64 - Visual Studio Pro 19 - v16.8.4 Autodesk Revit 2022

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (7 by maintainers)

Commits related to this issue

Most upvoted comments

I appreciate you all working on this. Preview3 (6.0.0) was the first install that got past the missing reference for Text.JSON but it was throwing this SSL Protocol error for me. I have downloaded the latest unstable version (20210521T094529 which doesn’t throw the SSL Protocol warning or at least doesn’t get there because its back missing references for Text.JSON 5.0.0.0 even with redirects for 5.0.0.2.

However, another option is to do runtime detection and select SslProtocol as a function of that (or even conditional compilation for .NET Standard 2.0). I still think it’s better for us to specify SslProtocol.None, and it would be a shame to not do that because of .NET Framework…

Sure, works for me.

I definitely agree with @vonzshik that a connection string param doesn’t make sense here.

However, another option is to do runtime detection and select SslProtocol as a function of that (or even conditional compilation for .NET Standard 2.0). I still think it’s better for us to specify SslProtocol.None, and it would be a shame to not do that because of .NET Framework…

@TorsionTools I’ve found this thread (robinrodricks/FluentFTP#452), which suggests that there are cases when SslProtocol.None might not be supported on .NET Framework due to it being disabled in OS.

In light of this, I think it’s easier to just revert 2d3c2dc, as adding a new connection string param just to fix this particular issue (note, that there is no such issue with .net core) seems to me a little bit overkill.

Yes, please. At the very least it will answer whether the problem is with Revit not supporting SslProtocols.None for some reason.