Migrations cannot be applied when project name contains non ASCII character
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 281
Description
## Error
When project name (i.e. assembly and namespace) contain a non-ascii character, the migrations cannot be applied from the running application (didn't try the CLI). The error is
```
fail: Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.MigrationsEndPointMiddleware[3]
The context type '\u0160.Data.ApplicationDbContext, \u0160, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' was not found in services. This usually means the context was not registered in services during startup. You probably want to call AddScoped<>() inside the UseServices(...) call in your application startup code.
```
The DbContext is registered and the error doesn't appear when the project name is ASCII only.
## How to reproduce
Create new web app from template called `Š`, switch to PostgreSQL (because the default Sqlite isn't applying migrations and magically works from start, I doubt the problem is with Npgsql)
```
dotnet new razor -n Š --auth Individual
cd Š
dotnet add package Npgsql.EntityFrameworkCore.PostgreSQL
```
* Change `options.UseSqlite(connectionString)` to `options.UseNpgsql(connectionString)` in Program.cs
* Change connection string in appsettings.json to a PostgreSQL server
* Navigate the website, attempt to login
* That errors out, because migrations weren't applied, click "Apply Migrations" which also fails with " An error occurred applying migrations, try applying them from the command line "
If the project is called `S` instead of `Š`, it works as expected (login fails, but then, clicking Apply Migrations works). For more precise reproducibility, I have attached both versions: [S.tar.gz](https://github.com/dotnet/efcore/files/11568557/S.tar.gz), [Š.tar.gz](https://github.com/dotnet/efcore/files/11568558/S.tar.gz).
The only difference in Program.cs is the namespace, I didn't touch the other files:
```
exyi@NaN /tmp> diff Š/Program.cs S/Program.cs
3c3
< using Š.Data;
---
> using S.Data;
```
### System and versions
EF Core version: 7.0.3
Npgsql version: 7.0.4
Target framework: net7.0
Operating system: Linux (Arch)
IDE: The Command Line Interface at al.
Contributor guide
Assessment
This issue has not been assessed yet.