Skip to main content

290 posts tagged with ".NET"

.NET Framework and Core for Application Development

View All Tags

Fixed: "Cannot convert string value 'Refund' from the database to any value in the mapped 'StockMovementType' enum." in EF Core

· 10 min read
Jagdish Kumawat
Founder @ Dewiride

One row in a table held a name my C# enum didn't have, and every query that read that table failed: System.InvalidOperationException: Cannot convert string value 'Refund' from the database to any value in the mapped 'StockMovementType' enum. Here's why EF Core refuses instead of guessing, how to find every bad value with one query, and how to keep them out.

Fixed: "An operation was scaffolded that may result in the loss of data. Please review the migration for accuracy." in EF Core

· 10 min read
Jagdish Kumawat
Founder @ Dewiride

An operation was scaffolded that may result in the loss of data. Please review the migration for accuracy. is a warning, not an error: the migration is created anyway, and nothing stops you from applying it. I got it on five migrations while building one EF Core model on MySQL, each time for a different reason. The one time I applied it without checking the data, the migration failed halfway.

Fixed: "A compatible .NET SDK was not found" (Requested SDK Version from global.json)

· 7 min read
Jagdish Kumawat
Founder @ Dewiride

After I edited a project's global.json, every dotnet command in the folder stopped working with "A compatible .NET SDK was not found", even though a newer .NET 10 SDK was installed. The message itself names the file that caused it. The fix was one word in global.json: the rollForward value decides whether a newer SDK may stand in for the requested one.

Fixed: "error CA1861: Prefer 'static readonly' fields over constant array arguments if the called method is called repeatedly and is not mutating the passed array" in an EF Core Migration

· 9 min read
Jagdish Kumawat
Founder @ Dewiride

The second migration I added to a .NET 10 project stopped the build with error CA1861. EF Core writes the columns of a two-column index as a constant array, the code analyzer asks for that array to be a static readonly field, and the project treats warnings as errors. The rule's own page says it's safe to suppress when the code runs once, which is what a migration does, so the fix is one setting that turns CA1861 off for migration files only.

Fixed: "Authentication to host '127.0.0.1' for user 'inventory_app' using method 'caching_sha2_password' failed with message: Access denied for user 'inventory_app'@'172.20.0.1' (using password: YES)" in .NET

· 7 min read
Jagdish Kumawat
Founder @ Dewiride

MySql.Data.MySqlClient.MySqlException (0x80004005): Authentication to host '127.0.0.1' for user 'inventory_app' using method 'caching_sha2_password' failed with message: Access denied for user 'inventory_app'@'172.20.0.1' (using password: YES) That's MySQL error 1045 as .NET reports it, wrapped in a longer sentence with two different addresses. Every part of it is a clue: who you tried to log in as, from where, how, and that a password was sent. Here's how to read it, and what it was in my case.

Fixed: "Unable to connect to any of the specified MySQL hosts" in .NET C#

· 7 min read
Jagdish Kumawat
Founder @ Dewiride

Unable to connect to any of the specified MySQL hosts is MySql.Data's message when it can't reach MySQL at all: it never got as far as checking a user name or password. The inner exception tells you more. I got it twice in a .NET C# program that connects to MySQL in Docker, for two different reasons, and four quick checks tell them apart.

Fixed: "Retrieval of the RSA public key is not enabled for insecure connections" Connecting .NET C# to MySQL

· 8 min read
Jagdish Kumawat
Founder @ Dewiride

Retrieval of the RSA public key is not enabled for insecure connections is one of the most confusing MySQL errors in .NET, because it comes and goes: the same connection string fails after MySQL restarts and works again later. The cause is MySQL's default sign-in method, caching_sha2_password, meeting a connection without TLS. This post shows it happening in a small .NET C# program, explains why it's intermittent, and fixes it the right way.

How to Connect a .NET C# Web API to a MySQL Database — Part 1: Connect with EF Core and a Secure Connection String

· 44 min read
Jagdish Kumawat
Founder @ Dewiride

A Web API needs somewhere to keep its data, and MySQL is one of the most popular places to keep it. This part connects an ASP.NET Core minimal API, written in .NET 10 and C#, to MySQL 9.7 through Entity Framework Core. It keeps the password out of the code, encrypts the connection, proves the connection works with a health check, and then looks at that same connection from inside MySQL so you can see exactly what happened.

How to Add Liveness and Readiness Health Checks to a .NET C# Web API

· 9 min read
Jagdish Kumawat
Founder @ Dewiride

A health check is a small endpoint that answers one question: is this API working? Hosting platforms, load balancers and monitoring tools call it every few seconds and act on the answer. This guide adds two of them to a .NET 10 C# minimal API, one that only checks that the API is running and one that also checks the database, and shows their real answers when the database goes down.

How to Store a Connection String in .NET C# with dotnet user-secrets

· 12 min read
Jagdish Kumawat
Founder @ Dewiride

A connection string usually contains a password, and appsettings.json is committed to Git with the rest of your code. .NET's Secret Manager, the dotnet user-secrets command, keeps secrets in a file in your user profile instead, and ASP.NET Core reads them as if they were in appsettings.json. This guide stores a MySQL connection string that way, shows every command with its real output, and explains how the same setting reaches the app outside development.