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.

dotnet publish command line started showing ADO issues at runtime

See original GitHub issue

Is 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, TaskCompletionSource1 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, TaskCompletionSource1 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:open
  • Created 10 months ago
  • Comments:15 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
yogigrantzcommented, May 25, 2023

@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

1reaction
yogigrantzcommented, Nov 19, 2022

@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 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

dotnet publish command - .NET CLI
dotnet publish - Publishes the application and its dependencies to a folder for deployment to a hosting system.
Read more >
Build, test, and deploy .NET Core apps - Azure Pipelines
Check the .NET Core SDK versions and runtime on your development machine and make sure they match the agent. You can include a...
Read more >
Publish a self-contained .NET app on Azure DevOps
Tutorial to build and publish a console application including the .NET (Core) framework from Azure DevOps Pipelines.
Read more >
Azure Pipelines: Dotnet publish fails with exit code 1 after ...
Found out that issue had nothing to do with the Azure Pipelines, it was caused by the package referenced in my .csproj:
Read more >
NET Core - how does the 'dotnet publish' command work?
Specifies the path for the output directory. If not specified, it defaults to ./bin/[configuration]/[framework]/publish/ for a framework- ...
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