im watching a course about asp.net and creating some kind of web
but everytime i try to do "dotnet ef migrations add init" it says "Unable to create a 'DbContext' of type 'RuntimeType'. The exception 'Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions`1[api.Data.ApplicationDBContext]' while attempting to activate 'api.Data.ApplicationDBContext'.' was thrown while attempting to create an instance. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728"
Search - Microsoft Bing
In a hole, there was a story
Today is Tolkien Reading Day. It's a time to dust




23 Replies
$code
To post C# code type the following:
```cs
// code here
```
Get an example by typing
$codegif
in chat
For longer snippets, use: https://paste.mod.gg/why
?
@ded like this?
ya
this all looks fine
have you configured your asp app to have a dbcontext in your
Startup.cs
file?am i suppose to have a startup.cs file
in most cases, yes

that is what asp will use to register services and configure the server
program?
show what's in program.cs
also, fwiw, i would recommend using visual studio if you are new to c#
not VSC
ik i was jsut watching a course and it did it in vscode so i didnt wanna do anything wrong
oh, top level statement asp project
hm?
wdym?
it isn't using the asp web host, so I'm guessing that's why you're getting that error
how do i use it?
haven't set up EF in an asp project like this, but you could try: https://learn.microsoft.com/en-us/ef/core/cli/dbcontext-creation?tabs=dotnet-core-cli#from-a-design-time-factory
okay thanks ill see
@Keswiik yo
actually
tysm bro
ive been trying to make this work
for litteraly 3 days

for an explanation on why you were getting errors, look at this section: https://learn.microsoft.com/en-us/ef/core/cli/dbcontext-creation?tabs=dotnet-core-cli#from-application-services
okay thank you
:PepoSalute:
Can you show the api.csproj file in this screenshot
I think they're banned