C
C#3y ago
demndev

✅ Build failed on `dotnet-ef database update`

10 Replies
FusedQyou
FusedQyou3y ago
Did you build and try the command afterwards? Can we see the code up to the point where you call AddDbContext?
demndev
demndevOP3y ago
yes:
public static IServiceCollection AddPersistence(this IServiceCollection services, IConfiguration configuration)
{
var connection = configuration.GetConnectionString("DefaultConnection")
?? throw new Exception("Unable to parse DbConnection configuration");
services.AddDbContext<IApplicationContext, ApplicationContext>(options => options.UseSqlite(connection));


return services;
}
public static IServiceCollection AddPersistence(this IServiceCollection services, IConfiguration configuration)
{
var connection = configuration.GetConnectionString("DefaultConnection")
?? throw new Exception("Unable to parse DbConnection configuration");
services.AddDbContext<IApplicationContext, ApplicationContext>(options => options.UseSqlite(connection));


return services;
}
FusedQyou
FusedQyou3y ago
And up to where you call AddPersistence?
demndev
demndevOP3y ago
var builder = WebApplication.CreateBuilder(args);
{
builder.Services
.AddApplication()
.AddPersistence(builder.Configuration)
.AddWeb(builder.Configuration);
}
var builder = WebApplication.CreateBuilder(args);
{
builder.Services
.AddApplication()
.AddPersistence(builder.Configuration)
.AddWeb(builder.Configuration);
}
FusedQyou
FusedQyou3y ago
Maybe try removing {}
demndev
demndevOP3y ago
no, but it builds when I call database update:
Build started...
Build started...
FusedQyou
FusedQyou3y ago
I believe EF injects code up to AddDbContext and it might not be able to properly do that
demndev
demndevOP3y ago
all the same
demndev
demndevOP3y ago
and again there's nothing helpful
demndev
demndevOP3y ago
miraculously the problem solved itself

Did you find this page helpful?