_From @livarcocc on March 21, 2018 7:10_
_From @wh1t3cAt1k on March 20, 2018 18:38_
cd into the directorydotnet builddotnet ef dbcontext listI see the dbcontexts list or a meaningful error.
I see an obscure error
Error:
An assembly specified in the application dependencies manifest (CoreRestaurants.deps.json) was not found:
package: 'CoreRestaurants', version: '1.0.0'
path: 'CoreRestaurants.dll'
It took me 2 days to figure out that the problem might be in access rights, and running the above stuff with sudo fixes the issue.
In hindsight it is surprising how I didn't guess it from the outset, but hey, everything is obvious in hindsight.
My point is that the error could be more descriptive so that people spend less time figuring out what went wrong. Perhaps there should be additional explicit checks made by the tool.
Note: the same issue with dotnet ef migrations list.
I into the ~/Projects/CoreRestaurants folder.
I run Mac OS 10.13.2 (17C88).
dotnet --info output:
.NET Command Line Tools (2.1.101)
Product Information:
Version: 2.1.101
Commit SHA-1 hash: 6c22303bf0
Runtime Environment:
OS Name: Mac OS X
OS Version: 10.13
OS Platform: Darwin
RID: osx.10.12-x64
Base Path: /usr/local/share/dotnet/sdk/2.1.101/
Microsoft .NET Core Shared Framework Host
Version : 2.0.6
Build : 74b1c703813c8910df5b96f304b0f2b78cdf194d
_Copied from original issue: dotnet/cli#8851_
_Copied from original issue: aspnet/EntityFrameworkCore#11367_
_From @livarcocc on March 21, 2018 7:10_
It is not clear to me if this is coming from EF trying to load the assemblies in the deps.json or if this is the host trying to load assemblies from the deps.json. If the latter, please, move the issue to core-setup.
Assuming it is the former, I am moving this to EF.
_From @bricelam on March 21, 2018 22:40_
Similar to #11320. I suspect the error occurs before any EF code gets invoked..
Moving per @livarcocc's request at https://github.com/dotnet/core-setup/issues/3965#issuecomment-378090171.
@divega I was unable to reproduce the issue locally on my mac. Using your attached repro, the ef commands work fine for my user account without sudo.
That error is likely coming from the host (dotnet) when it is trying to determine where each assembly in the deps.json file is located. Either the actual file (CoreRestaurants.dll) doesn't exist or it doesn't have permission to read that directory\file.
After you do a non-sudo build, does CoreRestaurants.dll exist in your bin/Debug/netcoreapp* folder?
Also can you try running export COREHOST_TRACE=1 and then running the ef commands? This may shed some light on the issue.
Thanks @steveharter. Please direct your questions to @wh1t3cAt1k, who reported the issue. I only moved the issue from another repo.
@wh1t3cAt1k please see my comment above
Setting this as future milestone for now, as this does not appear to be a critical 2.1 issue
It's happening to me on a window machine.
I have a C# project which is for an Azure Function. Tried to run
Scaffold-DbContext "Server=localhost;Database=Sales;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Tables Orders,OrderItems,OrderItemOptions
I get as result

Using
C#
EF CORE 2,1
Azure Function
Visual Studio 2017
cc @jeffschwMSFT @vitek-karas
@codechavez can you share the COREHOST_TRACE=1 logs and a repro? Thanks
It's happening to me, too, on a Windows machine. I'm running VS2017 v15.9.1 with everything else relevant fully up-to-date. I have a brand new Functions project (v2 preview, HTTP Trigger at setup) where I've added EFCore resources.
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.1.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.4" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.24" />
</ItemGroup>
In my scenario, I'm trying to run dotnet efcore dbcontext scaffold "connstrgoeshere" Microsoft.EntityFrameworkCore.SqlServer -o Database and I get that error.
To answer some earlier questions:
After you do a non-sudo build, does CoreRestaurants.dll exist in your bin/Debug/netcoreapp* folder?
Not exactly. The DLL is in the bin/Debug/netcoreapp2.1/bin folder for me.
can you share the COREHOST_TRACE=1 logs
I'm having trouble figuring out how to pipe these to a file with my somewhat complex command. This isn't getting it done. If somebody can tell me how to do this, I'll gladly share the log:
SET COREHOST_TRACE=1
dotnet efcore dbcontext scaffold "connstrgoeshere" Microsoft.EntityFrameworkCore.SqlServer -o Database > corehost.log
SET COREHOST_TRACE=0
Okay, I've figured out how to get one step further but with COREHOST_TRACE=1 set (2>corehost.log), it seems to freeze here:
--- Begin breadcrumb write
Number of breadcrumb files to write is 122
Breadcrumb thread write callback...Breadcrumbs will be written using a background thread
I had it freeze here yesterday as well, not piping it to a file, and it didn't finish even after hours of waiting.
It is happening in my project as well, i am running dotnet ef dbcontext scaffold "Server=.\sqlexpress;Database=xxxxx;User Id=xxxxx;Password=xxxxx;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -o Model
I tried to repro this, but no luck so far.
@214169 can you please try to set the COREHOST_TRACE=1 and run the command again with 2>corehost.log to redirect the stderr. And then share the log file (if you're comfortable doing so, it will contain local paths on your machine and also probably the DB password, feel free to scrub the DB password in the file)
Anybody who can repro this, can you share the project on which this reproes? And the version of sdk (dotnet --info) and the version of EF tools you're using?
Thank you very much for reporting the problem!
@vitek-karas
Run following cmd in attached project, you will be able to see error : dotnet ef dbcontext scaffold "Server=.\sqlexpress;Database=xyz;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -o Model
Thanks a lot - reproes - I'll look into it
The hang if COREHOST_TRACE=1 is set is caused by a bug in the Azure functions SDK. See Azure/azure-functions-vs-build-sdk#264.
I'll see if I can somehow workaround it to get to the actual failure.
I was able to get the core host trace with some hacks, but it doesn't show anything interesting. The error is correct, the file doesn't exist in the specified location.
The root cause of the failure is the combined behavior of the Azure Functions SDK and the EF tools. Azure Functions SDK redirects the build output to $(OutDir)/bin here. But right after the build is done it resets the OutDir property back to the original. I assume EF reads the property value and expects (sort of correctly) that the dll will be there.
I filed aspnet/EntityFrameworkCore#14084 on the EF side. Not sure if this belongs to EF or Azure Functions though.
Turns out to be a known issue with Azure Functions: Azure/azure-functions-host#2408
There's possible workaround mentioned in here: aspnet/EntityFrameworkCore#14084
The hang when tracing is on has a solution in 3.0 (it's possible to redirect tracing to a file). We're considering to port this change back to 2.2 as well.
After two days of agony I finally figured out the riddle of the sphynx. How to get azure functions to work with entity framework? Gadzooks Microsoft it shouldn't be this difficult! I ran into the same error as above. Here is an approach I finally tried and it worked:
Using Visual Studio 2019 community.
Create new solution with asp core class library project.
DO NOT START solution with azure function project!
Install Microsoft.EntityFramework.Tools, Design, SqlServer.
Version .NET Core 3.1 with worked for me.
Make sure library project is also set to 3.1.
Create Models folder and run scaffolding. I used -force -verbose just in case.
Voila this time the dependencies manifest missing message did not show!
Now add your azure functions project.
Make sure functions project is also set to 3.1.
Set a dependency from functions project to library project.
Builds and runs fine!
Also refreshes the entities models if rerun!
Thanks @jacktwork.
Cc @ajcvickers in case he isn鈥檛 subscribed this issue.
Thanks @divega
@jacktwork The difficulty of making Azure Functions work with different .NET versions and external packages is something that is being worked on. I'm not directly involved, but from what I have heard it will get better.
I was able to generate my DB Context and classes using EF Core Power Tools. This route is cleaner than having a solution/project outside of the function for maintaining the models.
I had this issue on Windows/VS19 .netCore2.2 with netstandard lib. The really annoying part was i was running add-migration in a project that was NOT the one it was complaining about..., even with "clean solution" i had to manually delete the obj and bin folders and restart VS and it worked. I assume somewhere in that mess it reset the $(OutDir)/bin vitek-karas above mentions? Anyway if that helps anyone...
My 5-cents
I had the same issue, and changed the start-up project to be the project where I wanted the Scaffold-DbContext to generate the model. This did the trick for me in a new Azure Function .Net Core 3.0 project
Yes it seems that if you leave the app as the function app in a sln with multiple projects it will fail/complain. Not just in the package manager drop down but the actual currently running project. This is a bit annoying when you have a library project in addition to the project you鈥檙e working on but at least it consistently works and you can continue using package manager console without having to reload.
@vestergaardj your solutions worked for me..
Most helpful comment
It's happening to me on a window machine.
I have a C# project which is for an Azure Function. Tried to run
Scaffold-DbContext "Server=localhost;Database=Sales;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Tables Orders,OrderItems,OrderItemOptionsI get as result

Using
C#
EF CORE 2,1
Azure Function
Visual Studio 2017