This issue is resolved by:
KB5003342 - FIX: SQL Server Express LocalDB can't start or connect to shared instances of SQL Server Express LocalDB 2019 or 2017
Assume that you use the SqlLocalDB feature in Microsoft SQL Server 2019 or 2017. In this situation, you can't start correctly or connect to a shared instance of SqlLocalDB.
This problem is fixed in the ...
As Aurora suggested, this is a bug in LocalDB >= 2017 and Microsoft doesn't seem to care so much about it. The reason is probably because LocalDb is not supposed to be used in production environments. The suggested workaround is good, but it needs to be done manually.
To overcome this issue in your software, you can implement the following workaround: