Search code examples
c#asp.netasp.net-core-webapiasp.net-core-7.0

Publishing ASP.NET Core 7 Web API on Windows Plesk - error: Could not load file or assembly 'Microsoft.Data.SqlClient'


When I publish my ASP.NET Core 7 Web API on the Windows Plesk host, everything works fine, but when I try to connect and run a query to SQL Server database which is on host, I get this error:

FileNotFoundException: Could not load file or assembly 'Microsoft.Data.SqlClient, Version=5.0.0.0...

enter image description here

I decided to install Microsoft.Data.SqlClient package (I don't know how to use it, I only installed it, but I still get the same error), and these are my packages:

enter image description here

I have two connection strings - one is in my DbContext:

enter image description here

The other one is in my appSettings.json (but there was no connection string on my appSettings.json by default, I added it manually):

enter image description here

I don't know which connection string is used on host, but on my local computer 'DBContext ConnectionString' was working, and I even removed "TrustServerCertificate=True" and I changed the "Database=" to "Initial Catalog=" on both connection strings, still same error.


Solution

  • I found the solution, in ASP.NET Core 6, 7 and 8 after publishing there will be a folder named 'runtimes', You're gonna need it with the project files to deploy on IIS or Hosts