dotnet / dotnet/aspnetcore

Migrations cannot be applied when project name contains non ASCII character

Open
#48,604 5 comments 0 reactions 0 assignees View on GitHub
area-middleware
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.