Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No DbContext was found in assembly 'ef' exception when assembly is named 'EF' in project.csproj file #8035

Closed
mziyabo opened this issue Mar 30, 2017 · 3 comments
Labels
closed-out-of-scope This is not something that will be fixed/implemented and the issue is closed. customer-reported

Comments

@mziyabo
Copy link

mziyabo commented Mar 30, 2017

Getting a No DbContext was found in assembly 'ef' exception when I run dotnet ef add InitialMigration -p EF.csproj -c MFIDataContext. This happened after I ran dotnet migrate. Prior to this It would have added the migration. Same error occurs when listing dbcontexts or migrations.

Exception message:
Stack trace:

Using project 'EF.csproj'.
Using startup project '/home/mziyabo/Documents/Projects/MFI/EF/EF.csproj'.
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=/tmp/tmpddFRok.tmp /verbosity:quiet /nologo EF.csproj
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=/tmp/tmp0OXR4U.tmp /verbosity:quiet /nologo /home/mziyabo/Documents/Projects/MFI/EF/EF.csproj
dotnet build /home/mziyabo/Documents/Projects/MFI/EF/EF.csproj /verbosity:quiet /nologo

Build succeeded.
0 Warning(s)
0 Error(s)

Time Elapsed 00:00:11.88
dotnet exec --depsfile /home/mziyabo/Documents/Projects/MFI/EF/bin/Debug/netcoreapp1.1/EF.deps.json --additionalprobingpath /home/mziyabo/.nuget/packages --runtimeconfig /home/mziyabo/Documents/Projects/MFI/EF/bin/Debug/netcoreapp1.1/EF.runtimeconfig.json /home/mziyabo/.nuget/packages/microsoft.entityframeworkcore.tools.dotnet/1.0.0/tools/netcoreapp1.0/ef.dll migrations add InitialMigration --assembly /home/mziyabo/Documents/Projects/MFI/EF/bin/Debug/netcoreapp1.1/EF.dll --startup-assembly /home/mziyabo/Documents/Projects/MFI/EF/bin/Debug/netcoreapp1.1/EF.dll --project-dir /home/mziyabo/Documents/Projects/MFI/EF/ --content-root /home/mziyabo/Documents/Projects/MFI/EF/ --data-dir /home/mziyabo/Documents/Projects/MFI/EF/bin/Debug/netcoreapp1.1/ --verbose --root-namespace EF
Using assembly 'EF'.
Using startup assembly 'EF'.
Using application base '/home/mziyabo/Documents/Projects/MFI/EF/bin/Debug/netcoreapp1.1'.
Using content root '/home/mziyabo/Documents/Projects/MFI/EF/'.
Using root namespace 'EF'.
Using project directory '/home/mziyabo/Documents/Projects/MFI/EF/'.
Using data directory '/home/mziyabo/Documents/Projects/MFI/EF/bin/Debug/netcoreapp1.1/'.
Finding DbContext classes...
Microsoft.EntityFrameworkCore.Design.OperationException: No DbContext was found in assembly 'ef'. Ensure that you're using the correct assembly and that the type is neither abstract nor generic.
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.FindContextType(String name)
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(String contextType)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
No DbContext was found in assembly 'ef'. Ensure that you're using the correct assembly and that the type is neither abstract nor generic.

Steps to reproduce

Add Assembly Line parameter as 'EF' to .csproj file containing EF code:

<AssemblyName>EF</AssemblyName>

Run line below in terminal:

dotnet ef add InitialMigration -p EF.csproj -c MFIDataContext

Further technical details

Command Line Tools (1.0.0-preview4-004233)
Information:
Version: 1.0.0-preview4-004233
Commit SHA-1 hash: 8cec61c6f7
Environment:
OS Name: ubuntu
OS Version: 16.04
OS Platform: Linux
RID: ubuntu.16.04-x64
Base Path: /usr/share/dotnet/sdk/1.0.0-preview4-004233

@mziyabo
Copy link
Author

mziyabo commented Mar 30, 2017

The runtime seems to search /.nuget/packages/microsoft.entityframeworkcore.tools.dotnet/1.0.0/tools/netcoreapp1.0/ef.dll for dbcontexts instead of my output dll /home/mziyabo/Documents/Projects/MFI/EF/bin/Debug/netcoreapp1.1/EF.dll

I am not sure about that but it could explain why it outputs the exception as: No DbContext was found in assembly 'ef'

Renaming my assembly in the project file to something else seems to resolve the issue.

@ajcvickers
Copy link
Member

@mziyabo We discussed this but the only thing we could really do here would be to throw a different exception if you uses ef as your assembly name. The end result would still be that you need to use a different assembly name to make things work. As of right now we don't feel there is enough value in doing this, but if we see this repeatedly causing confusion then we may revisit.

@ajcvickers ajcvickers added the closed-out-of-scope This is not something that will be fixed/implemented and the issue is closed. label Mar 31, 2017
@pstricks-fans
Copy link

I think the error message should be made more specific. I got the same problem yesterday.

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-out-of-scope This is not something that will be fixed/implemented and the issue is closed. customer-reported
Projects
None yet
Development

No branches or pull requests

3 participants