23

I'm running beta7 for everything, including EF 7. I'm trying to connect to my remote existing database using the ASP.NET 5 Application template project. My project.json looks like this:

{
  "webroot": "wwwroot",
  "userSecretsId": "aspnet5-XXX-409e9e37-b7bb-4185-b7aa-6dc336087524",
  "version": "1.0.0-*",

  "dependencies": {
    "EntityFramework.Commands": "7.0.0-beta7",
    "EntityFramework.SqlServer": "7.0.0-beta7",
    "Microsoft.AspNet.Authentication.Cookies": "1.0.0-beta7",
    "Microsoft.AspNet.Authentication.Facebook": "1.0.0-beta7",
    "Microsoft.AspNet.Authentication.Google": "1.0.0-beta7",
    "Microsoft.AspNet.Authentication.MicrosoftAccount": "1.0.0-beta7",
    "Microsoft.AspNet.Authentication.Twitter": "1.0.0-beta7",
    "Microsoft.AspNet.Diagnostics": "1.0.0-beta7",
    "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-beta7",
    "Microsoft.AspNet.Identity.EntityFramework": "3.0.0-beta7",
    "Microsoft.AspNet.Mvc": "6.0.0-beta7",
    "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta7",
    "Microsoft.AspNet.Server.IIS": "1.0.0-beta7",
    "Microsoft.AspNet.Server.WebListener": "1.0.0-beta7",
    "Microsoft.AspNet.StaticFiles": "1.0.0-beta7",
    "Microsoft.AspNet.Tooling.Razor": "1.0.0-beta7",
    "Microsoft.Framework.Configuration.Abstractions": "1.0.0-beta7",
    "Microsoft.Framework.Configuration.Json": "1.0.0-beta7",
    "Microsoft.Framework.Configuration.UserSecrets": "1.0.0-beta7",
    "Microsoft.Framework.Logging": "1.0.0-beta7",
    "Microsoft.Framework.Logging.Console": "1.0.0-beta7",
    "Microsoft.Framework.Logging.Debug" : "1.0.0-beta7",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-beta7"
  },

  "commands": {
    "web": "Microsoft.AspNet.Hosting --config hosting.ini",
    "ef": "EntityFramework.Commands"
  },

  "frameworks": {
    "dnx451": { },
    "dnxcore50": { }
  },

  "exclude": [
    "wwwroot",
    "node_modules",
    "bower_components"
  ],

  "publishExclude": [
    "node_modules",
    "bower_components",
    "**.xproj",
    "**.user",
    "**.vspscc"
  ],

  "scripts": {
   "prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ]
  }
}

Doing a search online it seemed that in order to accomplish what I wanted I needed to run the following command:

dnx ef dbcontext scaffold "ConnectionString" EntityFramework.SqlServer

Which I could not do because I had an issue which was solved as explained here: Using existing database with ASP.NET 5 and EF7 (beta 7)

Now I can finally get to run the command "dnx", but when I try running it with my connectionstring, which looks like this:

dnx ef dbcontext scaffold "Data Source=192.168.XX.XXX\devsql;Initial
Catalog=Development;Integrated Security=False;User ID=system;Password=XXX;"
EntityFramework.SqlServer

it gives me the following errors:

[ERROR] dnx : System.InvalidOperationException: Failed to resolve the
following dependencies for target framework 'DNXCore,Version=v5.0':
[ERROR] En línea: 1 Carácter: 1 [ERROR] + dnx ef dbcontext scaffold
"Data Source=192.168.XX.XXX\devsql;Initial Catalog=Dev ... [ERROR] +
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[ERROR]     + CategoryInfo          : NotSpecified:
(System.InvalidO...,Version=v5.0'::String) [], RemoteException [ERROR]
+ FullyQualifiedErrorId : NativeCommandError [ERROR]   [ERROR]    EntityFramework.Commands 7.0.0-beta7 [ERROR]   
EntityFramework.SqlServer 7.0.0-beta7 [ERROR]   
Microsoft.AspNet.Authentication.Cookies 1.0.0 [ERROR] -beta7 [ERROR]  
Microsoft.AspNet.Authentication.Facebook 1.0.0-beta7 [ERROR]   
Microsoft.AspNet.Authentication.Google 1.0.0-beta7 [ERROR]   
Microsoft.AspNet.Authentication.MicrosoftAccount 1.0.0-beta7 [ERROR]  
Microsoft.AspNet.Authentication.Twitter 1.0.0-beta7 [ERROR]   
Microsoft.AspNet.Diagnostics 1.0.0-beta7 [ERROR]   
Microsoft.AspNet.Diagnostics.Entity 7.0.0-beta7 [ERROR]   
Microsoft.AspNet.Identity.EntityFramework 3.0.0-beta7 [ERROR]   
Microsoft.AspNet.Mvc 6.0.0-beta7 [ERROR]   
Microsoft.AspNet.Mvc.TagHelpers 6.0.0-beta7 [ERROR]   
Microsoft.AspNet.Server.IIS 1.0.0-beta7 [ERROR]   
Microsoft.AspNet.Server.WebListener 1.0.0-beta7 [ERROR]   
Microsoft.AspNet.StaticFiles 1.0.0-beta7 [ERROR]   
Microsoft.AspNet.Tooling.Razor 1.0.0-beta7 [ERROR]   
Microsoft.Framework.Configuration.Abstractions 1.0.0-beta7 [ERROR]   
Microsoft.Framework.Configuration.Json 1.0.0-beta7 [ERROR]   
Microsoft.Framework.Configuration.UserSecrets 1.0.0-beta7 [ERROR]   
Microsoft.Framework.Logging 1.0.0-beta7 [ERROR]   
Microsoft.Framework.Logging.Console 1.0.0-beta7 [ERROR]   
Microsoft.Framework.Logging.Debug 1.0.0-beta7 [ERROR]   
Microsoft.VisualStudio.Web.BrowserLink.Loader 14.0.0-beta7 [ERROR] 
[ERROR]
C:\XXX\XXX\src\XXX\project.lock.json(1,0):
error: The expected lock file doesn't exist. Please run "dnu restore"
to generate a new lock file. [ERROR] Current runtime target framework:
'DNXCore,Version=v5.0 (dnxcore50)' [ERROR]  Version:     
1.0.0-beta7-15532 [ERROR]  Type:         CoreCLR [ERROR]  Architecture: x64 [ERROR]  OS Name:      Windows [ERROR]  OS Version: 
6.1 [ERROR]  [ERROR]    at Microsoft.Dnx.Runtime.DefaultHost.GetEntryPoint(String
applicationName) [ERROR]    at
Microsoft.Dnx.ApplicationHost.Program.ExecuteMain(DefaultHost host,
String applicationName, String[] args) [ERROR]    at
Microsoft.Dnx.ApplicationHost.Program.Main(String[] args) [ERROR] ---
End of stack trace from previous location where exception was thrown
--- [ERROR]    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [ERROR]
at Microsoft.Dnx.Runtime.Common.EntryPointExecutor.Execute(Assembly
assembly, String[] args, IServiceProvider serviceProvider) [ERROR]   
at Microsoft.Dnx.Host.Bootstrapper.RunAsync(List`1 args,
IRuntimeEnvironment env, FrameworkName targetFramework) [ERROR]    at
Microsoft.Dnx.Host.RuntimeBootstrapper.ExecuteAsync(String[] args,
FrameworkName targetFramework) [ERROR]    at
Microsoft.Dnx.Host.RuntimeBootstrapper.Execute(String[] args,
FrameworkName targetFramework) [ERROR]

Given the

[ERROR]
C:\XXX\XXX\src\XXX\project.lock.json(1,0):
error: The expected lock file doesn't exist. Please run "dnu restore"
to generate a new lock file.

I have tried running

PS C:\XXX\XXX> dnu restore
Microsoft .NET Development Utility CoreCLR-x64-1.0.0-beta7-15532

CACHE https://api.nuget.org/v3/index.json Restoring packages for
C:\XXX\XXX\src\XXX\project.json   CACHE
https://api.nuget.org/v3-flatcontainer/system.threading.threadpool/index.json
GET
https://api.nuget.org/v3-flatcontainer/system.net.sockets/index.json  
OK
https://api.nuget.org/v3-flatcontainer/system.net.sockets/index.json
1117ms Writing lock file
C:\XXX\XXX\src\XXX\project.lock.json Restore
complete, 2071ms elapsed

NuGet Config files used:
    C:\Users\XXX\AppData\Roaming\NuGet\NuGet.Config
    C:\XXX\XXX\NuGet.Config

Feeds used:
    https://api.nuget.org/v3-flatcontainer/

Which recreates the project.lock.json successfully, it seems (timestamp also reflects this). However, when I try running my scaffold script again, it keeps showing the same error shown above including the "expected lock file doesn't exist" part.

Any idea what's going wrong?

Community
  • 1
  • 1
erictrigo
  • 989
  • 2
  • 13
  • 41

6 Answers6

37

I faced the same problem, and fixed it by: - Right click on "References" - Select "Restore Packages"

Or Ctrl + Shilf + R

It will create/update the "project.lock.json" file, which includes a complete list of all of the NuGet packages the app is using. In my opinion, you shouldn't put it in the source control

Nhat Hong Ly
  • 618
  • 4
  • 15
4

Try this:

Close Visual Studio completely.

Open a Visual Studio Command Prompt window.

cd C:\XXX\XXX\src\XXX\

dnu restore

dnx ef dbcontext scaffold "ConnectionString" EntityFramework.SqlServer
Michael Rice
  • 1,173
  • 5
  • 13
1

If you are running this command on an application currently executing in a Windows Server Kernel environment, Core 5.0 will not work often. It can read some, but not create, especially if you host in IIS. I had this issue a lot, I found it best to just skip EntityFramework.Commands in main dependency, and jump down to

"frameworks":{
    "dnx451":{
          "dependencies":{
                 "EntityFramework.Commands":"7.0.0-beta7"
          }
      }
  ,"dnxcore50"...

also, make sure when you get ready to run dnx, run

dnvm use latest -r clr -arch {your server kernel arch} x64|x86

to ensure you are not trying to invoke coreclr for commands. that should fix the issue, and it has for me on a production server (because scaffolding the dbcontext is largely harmless)

Nathan Teague
  • 825
  • 6
  • 11
  • And also of note -- I have not had much luck at all with CoreCLR 50 and SqlServer. Currently investigating performance hit of running an API with dnx46, and my site applications on dnxcore50, and using rest data retrieval, just to amend the headaches. I use dnx46 btw, because it has the async exceptions that 451 is missing, which help a lot on a high I/O api. – Nathan Teague Sep 28 '15 at 17:07
1

I had the same problem, tried to remove the references and re add them but it failed. i went to ManageNugetPackage manager and removed the private internal nuget resource from the settings and restored my packages and it worked (i also deleted the old project.lock file)

Vijaya Malla
  • 209
  • 1
  • 2
  • 11
0

I have found if you create the visual studio solution folder on a UNC path this error will occur.

Often UNC paths map your Documents folder when using a windows on virtual machine (e.g. Parallels for Mac), and therefore visual studio will use this path by default for new solutions.

To fix the issue I moved the visual studio solution folder to the virtual machine disk drive, then reopened the project.

wal5hy
  • 654
  • 6
  • 8
0

I had similar issue with VS 2015 complaining about restore failure of AspNetCore references and one of the error messsages pointing to do a "dotnet restore". dotnet restore failed during the last steps. But,

The solution that worked was removing local nuget package feed reference using Nuget package Manager settings.

abhijoseph
  • 307
  • 1
  • 3
  • 5