C
C#3mo ago
oke

Trying to setup SQLite with EntityFramework (Discord Bot /w DSharpPlus)

I'm trying to setup SQLite for my discord bot, and to start the DB file, I tried using this command
PM> Add-Migration InitialCreate -Context LloydWarningSystem.Net.Entities.LloydContext
PM> Add-Migration InitialCreate -Context LloydWarningSystem.Net.Entities.LloydContext
LloydContext is my class that inherits DbContext. However, this command just builds my bot then runs it then gives an exception saying it cant find my service.
PM> Add-Migration InitialCreate -Context LloydWarningSystem.Net.Entities.LloydContext
Both Entity Framework Core and Entity Framework 6 are installed. The Entity Framework Core tools are running. Use 'EntityFramework6\Add-Migration' for Entity Framework 6.
Build started...
Build succeeded.
[!] Bot start @ 7/21/2024 2:46:06 PM (Debug build)
[2024-07-21 20:46:08 +00:00] [DSharpPlus.DiscordClient] [Info] DSharpPlus; version 5.0.0-nightly-02329+a9fe1468a51cabd82565a7f7e86d86ce1c428595
[!] Bot ready for commands.
An error occurred while accessing the Microsoft.Extensions.Hosting services. Continuing without the application service provider. Error: Timed out waiting for the entry point to build the IHost after 00:05:00. This timeout can be modified using the 'DOTNET_HOST_FACTORY_RESOLVER_DEFAULT_TIMEOUT_IN_SECONDS' environment variable.
Unable to create a 'DbContext' of type 'LloydWarningSystem.Net.Entities.LloydContext'. The exception 'Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions`1[LloydWarningSystem.Net.Entities.LloydContext]' while attempting to activate 'LloydWarningSystem.Net.Entities.LloydContext'.' was thrown while attempting to create an instance. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
PM> Add-Migration InitialCreate -Context LloydWarningSystem.Net.Entities.LloydContext
Both Entity Framework Core and Entity Framework 6 are installed. The Entity Framework Core tools are running. Use 'EntityFramework6\Add-Migration' for Entity Framework 6.
Build started...
Build succeeded.
[!] Bot start @ 7/21/2024 2:46:06 PM (Debug build)
[2024-07-21 20:46:08 +00:00] [DSharpPlus.DiscordClient] [Info] DSharpPlus; version 5.0.0-nightly-02329+a9fe1468a51cabd82565a7f7e86d86ce1c428595
[!] Bot ready for commands.
An error occurred while accessing the Microsoft.Extensions.Hosting services. Continuing without the application service provider. Error: Timed out waiting for the entry point to build the IHost after 00:05:00. This timeout can be modified using the 'DOTNET_HOST_FACTORY_RESOLVER_DEFAULT_TIMEOUT_IN_SECONDS' environment variable.
Unable to create a 'DbContext' of type 'LloydWarningSystem.Net.Entities.LloydContext'. The exception 'Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions`1[LloydWarningSystem.Net.Entities.LloydContext]' while attempting to activate 'LloydWarningSystem.Net.Entities.LloydContext'.' was thrown while attempting to create an instance. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
10 Replies
oke
oke3mo ago
This is how I start the service (According to what I found with the DSharpPlus documentation
var builder = DiscordClientBuilder.CreateDefault(token,
TextCommandProcessor.RequiredIntents
| SlashCommandProcessor.RequiredIntents
| DiscordIntents.MessageContents
| DiscordIntents.GuildMembers)
.ConfigureServices((services) =>
{
services.AddDbContext<LloydContext>(options =>
{
options.UseSqlite(connectionString);
});

Services = services.BuildServiceProvider();
});
var builder = DiscordClientBuilder.CreateDefault(token,
TextCommandProcessor.RequiredIntents
| SlashCommandProcessor.RequiredIntents
| DiscordIntents.MessageContents
| DiscordIntents.GuildMembers)
.ConfigureServices((services) =>
{
services.AddDbContext<LloydContext>(options =>
{
options.UseSqlite(connectionString);
});

Services = services.BuildServiceProvider();
});
I have never done anything like this, so I'm very lost. I tried following tutorials on the DSharpPlus documentation (Even their example bots), but it didn't help too much.
Angius
Angius3mo ago
Both Entity Framework Core and Entity Framework 6 are installed
Start by deleting EF6
jcotton42
jcotton423mo ago
EF6 runs on modern .NET?
oke
oke3mo ago
i removed all packages related to EF6, and now it's just running my bot and doing nothing within the package manager console. It's been open for ~5 minutes.
jcotton42
jcotton423mo ago
Design-time DbContext Creation - EF Core
Strategies for creating a design-time DbContext with Entity Framework Core
oke
oke3mo ago
right as i said that, it threw an exception
An error occurred while accessing the Microsoft.Extensions.Hosting services. Continuing without the application service provider. Error: Timed out waiting for the entry point to build the IHost after 00:05:00. This timeout can be modified using the 'DOTNET_HOST_FACTORY_RESOLVER_DEFAULT_TIMEOUT_IN_SECONDS' environment variable.
Unable to create a 'DbContext' of type 'LloydWarningSystem.Net.Entities.LloydContext'. The exception 'Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions`1[LloydWarningSystem.Net.Entities.LloydContext]' while attempting to activate 'LloydWarningSystem.Net.Entities.LloydContext'.' was thrown while attempting to create an instance. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
An error occurred while accessing the Microsoft.Extensions.Hosting services. Continuing without the application service provider. Error: Timed out waiting for the entry point to build the IHost after 00:05:00. This timeout can be modified using the 'DOTNET_HOST_FACTORY_RESOLVER_DEFAULT_TIMEOUT_IN_SECONDS' environment variable.
Unable to create a 'DbContext' of type 'LloydWarningSystem.Net.Entities.LloydContext'. The exception 'Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions`1[LloydWarningSystem.Net.Entities.LloydContext]' while attempting to activate 'LloydWarningSystem.Net.Entities.LloydContext'.' was thrown while attempting to create an instance. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
jcotton42
jcotton423mo ago
i'd use the design-time factory option From application services is the most ideal option though.
oke
oke3mo ago
i dont know what that means
jcotton42
jcotton423mo ago
look at my link
oke
oke3mo ago
i did, but i still dont know what to do ive never dealt with services before and i dont know how to use that with dsharpplus
Want results from more Discord servers?
Add your server