Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 18, 2025

Fixes the issue where the Clean Architecture template web project cannot be run directly on Linux because it attempts to use LocalDB (SQL Server), which is not supported on non-Windows platforms.

Changes Made

  1. InfrastructureServiceExtensions.cs: Modified to detect the operating system and skip the DefaultConnection (LocalDB) on non-Windows platforms, automatically falling back to SQLite. Added support for a USE_SQL_SERVER environment variable to force SQL Server mode when needed (e.g., for functional tests).

  2. MiddlewareConfig.cs: Updated database migration logic to use EnsureCreated() for SQLite databases (development/local scenarios) and Migrate() for SQL Server (production scenarios).

  3. appsettings.json: Updated comments to clarify the cross-platform behavior of connection strings.

  4. CustomWebApplicationFactory.cs: Updated functional tests to set the USE_SQL_SERVER environment variable and configure the SQL Server connection from Testcontainers, ensuring tests work cross-platform.

Testing

  • ✅ Web app runs successfully on Linux using SQLite
  • ✅ All unit tests pass (12/12)
  • ✅ All integration tests pass (3/3)
  • ✅ All functional tests pass (3/3)

The template now works seamlessly on Linux, macOS, and Windows without any manual configuration changes.

Fixes #977

Original prompt

This section details on the original issue you should resolve

<issue_title>Clean architecture template web project cannot be run directly on linux</issue_title>
<issue_description>

  • .NET SDK Version: 10.0.100 [/usr/share/dotnet/sdk]
  • Linux distribution: Arch Linux
  • Uname -a output: Linux ARCHDESKTOP 6.17.7-arch1-1 ardalis/CleanArchitecture#1 SMP PREEMPT_DYNAMIC Sun, 02 Nov 2025 17:27:22 +0000 x86_64 GNU/Linux

Steps to Reproduce:

  1. dotnet new install Ardalis.CleanArchitecture.Template
  2. dotnet new clean-arch -o ArdalisCleanArchitecture
  3. cd ArdalisCleanArchitecture
  4. dotnet run --project src/ArdalisCleanArchitecture.Web/

Result:

Using launch settings from src/ArdalisCleanArchitecture.Web/Properties/launchSettings.json...
Building...
info: Program[0]
      Starting web host
info: Program[0]
      Options were configured
info: Program[0]
      Infrastructure services registered
info: Program[0]
      Registering Mediator SourceGen and Behaviors
info: Program[0]
      Mediator Source Generator and Email Sender services registered
info: FastEndpoints.StartupTimer[1]
      Registered 5 endpoints in 83 milliseconds.
[12:08:09 INF] Registered 5 endpoints in 83 milliseconds.
[12:08:09 INF] Registered 5 endpoints in 83 milliseconds.
info: Program[0]
      Applying database migrations...
[12:08:09 INF] Applying database migrations...
[12:08:09 INF] Applying database migrations...
fail: Program[0]
      An error occurred migrating the DB. LocalDB is not supported on this platform.
      System.PlatformNotSupportedException: LocalDB is not supported on this platform.
         at Microsoft.Data.SqlClient.ManagedSni.LocalDB.GetLocalDBConnectionString(String localDbInstance)
         at Microsoft.Data.SqlClient.ManagedSni.SniProxy.GetLocalDBDataSource(String fullServerName, Boolean& error)
         at Microsoft.Data.SqlClient.ManagedSni.SniProxy.CreateConnectionHandle(String fullServerName, TimeoutTimer timeout, Byte[]& instanceName, ResolvedServerSpn& resolvedSpn, String serverSPN, Boolean flushCache, Boolean async, Boolean parallel, Boolean isIntegratedSecurity, SqlConnectionIPAddressPreference ipPreference, String cachedFQDN, SQLDNSInfo& pendingDNSInfo, Boolean tlsFirst, String hostNameInCertificate, String serverCertificateFilename)
         at Microsoft.Data.SqlClient.ManagedSni.TdsParserStateObjectManaged.CreatePhysicalSNIHandle(String serverName, TimeoutTimer timeout, Byte[]& instanceName, ResolvedServerSpn& resolvedSpn, Boolean flushCache, Boolean async, Boolean parallel, SqlConnectionIPAddressPreference iPAddressPreference, String cachedFQDN, SQLDNSInfo& pendingDNSInfo, String serverSPN, Boolean isIntegratedSecurity, Boolean tlsFirst, String hostNameInCertificate, String serverCertificateFilename)
         at Microsoft.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, TimeoutTimer timeout, SqlConnectionString connectionOptions, Boolean withFailover)
         at Microsoft.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, 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, IDbConnectionPool pool, Func`3 accessTokenCallback)
         at Microsoft.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionPoolGroupProviderInfo poolGroupProviderInfo, IDbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
         at Microsoft.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(IDbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
         at Microsoft.Data.SqlClient.ConnectionPool.WaitHandleDbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
         at Microsoft.Data.SqlClient....

</details>

- Fixes ardalis/CleanArchitecture#977

<!-- START COPILOT CODING AGENT TIPS -->
---

💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey).

@ardalis
Copy link
Owner

ardalis commented Nov 18, 2025

@copilot resume work; git issues should be resolved.

- Skip LocalDB connection on non-Windows platforms in InfrastructureServiceExtensions
- Use EnsureCreated for SQLite, Migrate for SQL Server in MiddlewareConfig
- Update appsettings.json comments to clarify cross-platform behavior
- Update functional tests to force SQL Server mode on Linux via environment variable

Co-authored-by: ardalis <[email protected]>
Copy link
Contributor Author

Copilot AI commented Nov 18, 2025

@copilot resume work; git issues should be resolved.

I've completed the fix for running the Clean Architecture template on Linux. The changes are in commit f112f95.

Summary of changes:

  1. Modified infrastructure to skip LocalDB connection on non-Windows platforms, using SQLite instead
  2. Updated database migration logic to use EnsureCreated() for SQLite and Migrate() for SQL Server
  3. Updated functional tests to work cross-platform by forcing SQL Server mode via environment variable

Testing:

  • ✅ Web app runs successfully on Linux using SQLite
  • ✅ All unit tests pass (12/12)
  • ✅ All integration tests pass (3/3)
  • ✅ All functional tests pass (3/3)

The template now works seamlessly on Linux, macOS, and Windows without any manual configuration changes.

Copilot AI changed the title [WIP] Fix running clean architecture template on Linux Fix running clean architecture template on Linux Nov 18, 2025
Copilot finished work on behalf of ardalis November 18, 2025 22:17
@ardalis ardalis marked this pull request as ready for review November 18, 2025 23:53
@ardalis ardalis merged commit dd71d99 into main Nov 20, 2025
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clean architecture template web project cannot be run directly on linux

2 participants