EF Core error: The certificate chain was issued by an authority that is not trusted.

I am doing local development of a .NET 9 Web API. It’s using a local instance of SqlServer Express with Entity Framework Core. However, after setting up my DBContext and generating my Migrations for the first time, when I went to run the dotnet ef database update command, I received the follow error message:

Microsoft.Data.SqlClient.SqlException (0x80131904): A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 – The certificate chain was issued by an authority that is not trusted.)

While this looks intimidating, it’s actually pretty easy to fix. The problem was with my ConnectionString. The ConnectionString looked like this:

"ConnectionStrings": {
    "default": "Server=MYPC\\SQLEXPRESS;Database=DemoDB;User Id=SA;Password=SuperSecretPassword;"
  }

Unfortunately for local development, I was missing 2 things Trusted_Connection=True;TrustServerCertificate=True;. Once I made my ConnectionString look like this:

"ConnectionStrings": {
    "default": "Server=MYPC\\SQLEXPRESS;Database=DemoDB;User Id=SA;Password=SuperSecretPassword;Trusted_Connection=True;TrustServerCertificate=True;"
  }

All I had to do was rerun my dotnet ef database update command and everything functioned as planned.

Debugging C# Web API for first time in VS Code — fix “don’t have an extension for debugging XML” error

I am trying to run the VS Code debugger for the first time for my .NET 9 web api. When I hit F5 it doesn’t start debugging and I get this message:

You don’t have an extension for debugging XML. Should we find a XML extension in the Marketplace?

So to fix this issue, I asked Github Copilot what to do to make it work. This was it’s response.

Step-by-step solution:

1. Install the official C# extension (if not already done).
2. Avoid focusing on your .csproj file when starting debugging—open one of your C# source files.
3. Create a launch configuration file to explicitly start debugging your web API.

And this was the launch.json file it created.

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": ".NET Launch Web API",
      "type": "coreclr",
      "request": "launch",
      "preLaunchTask": "build",
      "program": "${workspaceFolder}/dotnetapivue3.Server/bin/Debug/net9.0/dotnetapivue3.Server.dll",
      "args": [],
      "cwd": "${workspaceFolder}/dotnetapivue3.Server",
      "stopAtEntry": false,
      "serverReadyAction": {
        "action": "openExternally",
        "pattern": "\\bNow listening on:\\s+(https?://\\S+)"
      },
      "env": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  ]
}

I added the file to my project then, opened a controller file. Launched the debugger. After that, the project loaded as expected and I was able to set break points for debugging.