If you create new project like x new react-spa MyCompany.MyApp, the resulting generated block of code in Configure.Db.cs looks like this:
// $ dotnet ef migrations add CreateIdentitySchema
// $ dotnet ef database update
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlite(connectionString, b => b.MigrationsAssembly(nameof(MyCompany.MyApp))));
Because of how nameof operator works, it only passes "MyApp" as assembly name, even though full assembly name is "MyCompany.MyApp".
This causes running any dotnet ef command fail with error Could not load file or assembly 'MyApp, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
Changing the code to use string litteral with full assembly name or getting assembly name through reflection fixes the issue.
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlite(connectionString, b => b.MigrationsAssembly("MyCompany.MyApp")));
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlite(connectionString, b => b.MigrationsAssembly(Assembly.GetAssembly(typeof(ConfigureDb))?.FullName)));
If you create new project like
x new react-spa MyCompany.MyApp
, the resulting generated block of code in Configure.Db.cs looks like this:Because of how
nameof
operator works, it only passes "MyApp" as assembly name, even though full assembly name is "MyCompany.MyApp".This causes running any
dotnet ef
command fail with errorCould not load file or assembly 'MyApp, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
Changing the code to use string litteral with full assembly name or getting assembly name through reflection fixes the issue.
https://github.com/NetCoreTemplates/react-spa/blob/fda9be1e7d1c2b85ba4a221647f42c492736caa5/MyApp/Configure.Db.cs#L23