Aug 31, 2020
Per Djurner

Emojis in .NET Core / MySQL

To support emojis when using MySQL in .NET Core (version 2.2 in my case) you need to do a few things.

First of all, add CharSet=utf8mb4; to your database connection string. In other words, your code in Startup.cs should look something like this.

string db = @"Server=domain.com;Database=db;Uid=user;Pwd=pass;CharSet=utf8mb4;";
services.AddDbContext<AppDbContext>(options => options.UseMySQL(db));

You also need to make a couple of database changes. The charset needs to be set to utf8mb4 both for the column you are storing the emojis in and as the default for the entire database.

Home