dotnet publish command line started showing ADO issues at runtime
See original GitHub issueIs there an existing issue for this?
- I have searched the existing issues
Describe the bug
All along I have been able to publish a single executable console programs with command line like this:
dotnet publish <ProgramName> -o C:\Temp\publish2 /p:PublishSingleFile=true /p:PublishTrimmed=true --runtime win-x64
And the executable would run without any problem, even if it uses Microsoft.Data.SqlClient library. I believe the last time it worked was with Microsoft.Data.SqlClient 5.0.0
Now, when I run that dotnet command line and the program is trying to Open a SQL connection, I got this error:
SourceObject: Microsoft.Data.SqlClient Type: TypeLoadException StackTrace: (shown in the exception error section)
Expected Behavior
It should just open the SqlConnection without any error.
When I publish with Visual Studio with Framwork-dependent x64 to produce a single executable, it runs fine and would open the SqlConnection without any error.
I believe the dotnet command line publish should produce the exact same executable with Visual Studio publish. This is important, in case Visual Studio publish has issues then we should be able to fall back to the command line publish
Steps To Reproduce
Take any console program that uses Microsoft.Data.SqlClient 5.0.1, SqlConnection, and .Open() method, and publish it with that command line. Then run that executable and see if the Open() method would open sql connection successfully
Exceptions (if any)
at Microsoft.Data.SqlClient.SNINativeMethodWrapper.SNIAddProvider(SNIHandle pConn, ProviderEnum ProvNum, AuthProviderInfo& pInfo)
at Microsoft.Data.SqlClient.TdsParserStateObjectNative.EnableSsl(UInt32& info, Boolean tlsFirst)
at Microsoft.Data.SqlClient.TdsParser.EnableSsl(UInt32 info, SqlConnectionEncryptOption encrypt, Boolean integratedSecurity)
at Microsoft.Data.SqlClient.TdsParser.ConsumePreLoginHandshake(SqlConnectionEncryptOption encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean& marsCapable, Boolean& fedAuthRequired, Boolean tlsFirst)
at Microsoft.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnectionString connectionOptions, Boolean withFailover)
at Microsoft.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover)
at Microsoft.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout)
at Microsoft.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance)
at Microsoft.Data.SqlClient.SqlInternalConnectionTds…ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling, String accessToken, DbConnectionPool pool)
at Microsoft.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
at Microsoft.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
at Microsoft.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at Microsoft.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) at Microsoft.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource
1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at Microsoft.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions) at Microsoft.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource
1 retry, DbConnectionOptions userOptions)
at Microsoft.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry, SqlConnectionOverrides overrides)
at Microsoft.Data.SqlClient.SqlConnection.Open(SqlConnectionOverrides overrides)
at Microsoft.Data.SqlClient.SqlConnection.Open()
.NET Version
.net 6
Anything else?
No response
Issue Analytics
- State:
- Created 10 months ago
- Comments:15 (5 by maintainers)
@weberms : Yes for CI/CD for single executable, so far Microsoft.Data.SqlClient 4.1 seems to be the latest version that works. But for web applications with all dlls expanded, I’m able to use 5.x
@lcheunglci : no worries, for now I can publish the console app / single .exe using VS 2022 Publish button. I could downgrade also, but I’d rather just use the publish button for now until the fix is released. Thank you so much for looking into this 😃