dotnet / efcore

EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
https://docs.microsoft.com/ef/
MIT License
13.76k stars 3.18k forks source link

CLI commands throw "Could not load type 'System.ConsoleColor'" on execution #6250

Closed KCGCJohnJones closed 8 years ago

KCGCJohnJones commented 8 years ago

Steps to reproduce

Follwing the guide at https://docs.efproject.net/en/latest/platforms/aspnetcore/existing-db.html

The issue

Every step completes correctly up until:

Scaffold-DbContext "Server=someserver;Database=SomeDatabaseContext;User ID=someuser;Password=somepassword;"  Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models

dotnet flashes a white box on the screen Exception message: Stack trace:

Unhandled Exception: System.TypeInitializationException: The type initializer for 'Microsoft.DotNet.Cli.Utils.Reporter' threw an exception. ---> System.TypeLoadException: Could not load type 'System.ConsoleColor' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.    at Microsoft.DotNet.Cli.Utils.Reporter..ctor
    at Microsoft.DotNet.Cli.Utils.Reporter..cctor()
   --- End of inner exception stack trace ---
   at Microsoft.DotNet.Cli.Utils.Reporter.get_Error()
   at Microsoft.EntityFrameworkCore.Tools.Program.Main(String[] args)

If I add -Verbose.

Using startup project 'src\WebApplication1'
Working directory: D:\MyPath\WebApplication1\src\WebApplication1
Executing command: dotnet ef '--startup-project' 'D:\MyPath\WebApplication1\src\WebApplication1' '--configuration' 'Debug' '--build-base-path' '.\bin' 'dbcontext' 'scaffold' 'Server=SomeServer;Database=SomeDatabase.Context;User ID=SomeUser;Password=SomePassword;' 'Microsoft.EntityFrameworkCore.SqlServer' '--output-dir' 'Models' '--verbose'

Further technical details

EF Core version: (found in project.json or packages.config) Operating system: Win10 64bit Visual Studio version: Microsoft Visual Studio Professional 2015 Version 14.0.25425.01 Update 3 Microsoft .NET Framework Version 4.6.01038

Installed Version: Professional LightSwitch for Visual Studio 2015 00325-60000-14851-AA224 Microsoft LightSwitch for Visual Studio 2015 Microsoft Visual Studio Tools for Applications 2015 00325-60000-14851-AA224 Microsoft Visual Studio Tools for Applications 2015 Visual Basic 2015 00325-60000-14851-AA224 Microsoft Visual Basic 2015 Visual C# 2015 00325-60000-14851-AA224 Microsoft Visual C# 2015 Visual C++ 2015 00325-60000-14851-AA224 Microsoft Visual C++ 2015 Visual F# 2015 00325-60000-14851-AA224 Microsoft Visual F# 2015 Windows Phone SDK 8.0 - ENU 00325-60000-14851-AA224 Windows Phone SDK 8.0 - ENU ASP.NET and Web Tools 2015.1 14.1.20624.0 ASP.NET and Web Tools 2015.1 ASP.NET Web Frameworks and Tools 2012.2 4.1.41102.0 For additional information, visit http://go.microsoft.com/fwlink/?LinkID=309563 ASP.NET Web Frameworks and Tools 2013 5.2.40314.0 For additional information, visit http://www.asp.net/ Azure App Service Tools v2.9 14.0.20316.0 Azure App Service Tools v2.9 Azure Data Lake Node 1.0 This package contains the Data Lake integration nodes for Server Explorer. Azure Data Lake Tools for Visual Studio 2.0.6000.0 Microsoft Azure Data Lake Tools for Visual Studio Bundler & Minifier 2.1.258 Adds support for bundling and minifying JavaScript, CSS and HTML files in any project. Clang with Microsoft CodeGen 14.0.25515 Clang with Microsoft CodeGen Common Azure Tools 1.8 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools. DataFactoryProject 1.0 Microsoft Data Factory Package GitHub.VisualStudio 1.0 A Visual Studio Extension that brings the GitHub Flow into Visual Studio. JavaScript Language Service 2.0 JavaScript Language Service JavaScript Project System 2.0 JavaScript Project System JetBrains ReSharper Ultimate 2016.1.2 Build 105.0.20160522.80219 JetBrains ReSharper Ultimate package for Microsoft Visual Studio. For more information about ReSharper Ultimate, visit http://www.jetbrains.com/resharper. Copyright © 2016 JetBrains, Inc. KofePackagePackage Extension 1.0 KofePackagePackage Visual Studio Extension Detailed Info Microsoft .NET Core Tools (Preview 2) 14.1.20624.0 Microsoft .NET Core Tools (Preview 2) Microsoft Azure Data Factory Node Node 1.0 Azure Data Factory extension for Visual Studio Server Explorer. Microsoft Azure HDInsight HQL Service 2.0.6000.0 Language service for Hive query Microsoft Azure HDInsight Tools for Visual Studio 2.0.6000.0 An integrated development environment for HDInsight application development. Microsoft Azure Mobile Services Tools 1.4 Microsoft Azure Mobile Services Tools Microsoft Azure Tools 2.9 Microsoft Azure Tools for Microsoft Visual Studio 2015 - v2.9.40323.3 Microsoft Azure Tools 2.8 Microsoft Azure Tools for Microsoft Visual Studio 2015 - v2.8.31121.1 Microsoft MI-Based Debugger 1.0 Provides support for connecting Visual Studio to MI compatible debuggers NuGet Package Manager 3.5.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/. Office Developer Tools for Visual Studio 2015 ENU 14.0.23025 Microsoft Office Developer Tools for Visual Studio 2015 ENU Open Command Line 2.1.175 Opens a command line at the root of the project. Support for all consoles such as CMD, PowerShell, Bash etc. Provides syntax highlighting, Intellisense and execution of .cmd and .bat files. PreEmptive Analytics Visualizer 1.2 Microsoft Visual Studio extension to visualize aggregated summaries from the PreEmptive Analytics product. Python Tools for Visual Studio 2.2.40623.00 Python Tools for Visual Studio provides IntelliSense, projects, templates, Interactive windows, and other support for Python developers. Python Tools for Visual Studio - Django Integration 2.2.40623.00 Provides templates and integration for the Django web framework. Python Tools for Visual Studio - Profiling Support 2.2.40623.00 Profiling support for Python projects. SQL Server Analysis Services 13.0.1605.88 Microsoft SQL Server Analysis Services Designer Version 13.0.1605.88 SQL Server Data Tools 14.0.60629.0 Microsoft SQL Server Data Tools SQL Server Integration Services Microsoft SQL Server Integration Services Designer Version 13.0.1601.5 SQL Server Reporting Services 13.0.1605.88 Microsoft SQL Server Reporting Services Designers Version 13.0.1605.88 ToolWindowHostedEditor 1.0 Hosting json editor into a tool window TypeScript 1.8.36.0 TypeScript tools for Visual Studio Visual C++ for Cross Platform Mobile Development (Android) 14.0.25401.00 Visual C++ for Cross Platform Mobile Development (Android) Visual C++ for Cross Platform Mobile Development (iOS) 14.0.25401.00 Visual C++ for Cross Platform Mobile Development (iOS) Visual Studio Tools for Apache Cordova Update 10 Visual Studio Tools for Apache Cordova Visual Studio Tools for Universal Windows Apps 14.0.25527.01 The Visual Studio Tools for Universal Windows apps allow you to build a single universal app experience that can reach every device running Windows 10: phone, tablet, PC, and more. It includes the Microsoft Windows 10 Software Development Kit. Web Essentials 2015.3 3.0.230 Adds many useful features to Visual Studio for web developers. Requires Visual Studio 2015 Workflow Manager Tools 1.0 1.0 This package contains the necessary Visual Studio integration components for Workflow Manager. Xamarin 4.1.1.3 (34a92cd) Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android. Xamarin.Android 6.1.1.1 (7db2aac) Visual Studio extension to enable development for Xamarin.Android. Xamarin.iOS 9.8.1.4 (3cf8aae) Visual Studio extension to enable development for Xamarin.iOS.

Other details about my project setup:

{
  "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.0",
      "type": "platform"
    },
    "Microsoft.ApplicationInsights.AspNetCore": "1.0.0",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0",
    "Microsoft.AspNetCore.Mvc": "1.0.0",
    "Microsoft.AspNetCore.Razor.Tools": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Logging": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
    "Microsoft.EntityFrameworkCore.SqlServer.Design": "1.0.0"
  },

    "tools": {
        "BundlerMinifier.Core": "2.0.238",
        "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
        "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
        "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
    },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ]
    }
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "Views",
      "Areas/**/Views",
      "appsettings.json",
      "web.config"
    ]
  },

  "scripts": {
    "prepublish": [ "bower install", "dotnet bundle" ],
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}
divega commented 8 years ago

@natemcmaster could you please check if you can repro this?

natemcmaster commented 8 years ago

@KCGCJohnJones I'm guessing this is https://github.com/dotnet/cli/issues/2528. Can you zip up and share the following files?

%USERPROFILE%\.nuget\packages\.tools\Microsoft.EntityFrameworkCore.Tools\1.0.0-preview2-final\netcoreapp1.0\project.lock.json
%USERPROFILE%\.nuget\packages\.tools\Microsoft.EntityFrameworkCore.Tools\1.0.0-preview2-final\netcoreapp1.0\Microsoft.EntityFrameworkCore.Tools.deps.json

Then, delete %USERPROFILE%\.nuget\packages\.tools\Microsoft.EntityFrameworkCore.Tools\1.0.0-preview2-final\ and re-run NuGet package restore.

KCGCJohnJones commented 8 years ago

netcoreapp1.0.zip Sure thing. Had the same result.

natemcmaster commented 8 years ago

Thanks @KCGCJohnJones. The deps.json file you shared in the zip (%USERPROFILE%\.nuget\packages\.tools\Microsoft.EntityFrameworkCore.Tools\1.0.0-preview2-final\netcoreapp1.0\Microsoft.EntityFrameworkCore.Tools.deps.json) shows that .NET Core CLI is resolving .NET Framework dependencies instead of .NET Core dependencies for this tools package. cc @piotrpMSFT

Two questions:

(1) Can you share the full version info about the .NET Core CLI do you have installed? (Execute dotnet --info in the Package Manager Console window). Although it appears you have the Preview 2 version installed, it is still possible EF Core commands are finding the wrong version.

(2) To be 100% sure we're not , your project.json tools section does not use "imports", right? It should only have the tool name and version:

    "tools": {
        "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
    },

I'm just trying to verify that you're not encountering this known issue: https://github.com/aspnet/EntityFramework/issues/5458#issuecomment-221912806

KCGCJohnJones commented 8 years ago

PM> dotnet --info .NET Command Line Tools (1.0.0-preview1-002702)

Product Information: Version: 1.0.0-preview1-002702 Commit Sha: 6cde21225e

Runtime Environment: OS Name: Windows OS Version: 10.0.10586 OS Platform: Windows RID: win10-x64 PM>

"tools": { "BundlerMinifier.Core": "2.0.238", "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final", "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final", "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final" },

Here are my settings.

natemcmaster commented 8 years ago

@KCGCJohnJones can you updating to .NET CLI preview 2? https://www.microsoft.com/net/core#windows If you already have preview 2 installed, try uninstalling preview 1. Then repeat the instructions in https://github.com/aspnet/EntityFramework/issues/6250#issuecomment-238339524 (delete the files and re-run restore.)

KCGCJohnJones commented 8 years ago

I ended up uninstalling both preview 1 and 2.

After I uninstalled preview 1 I kept getting "Scaffold-DbContext" is not recognized as the name of a cmdlet. So I uninstalled preview 2 as well.

When I re-installed preview I got an error stating to restart windows due to un finished installation.

After a reboot I tried to install preview2 and got an error stating install had failed due to incomplete visual studio 2015 update 3. I googled this error and found an article that stated to run DotNetCore.1.0.0-VS2015Tools.Preview2.exe SKIP_VSU_CHECK=1.

This got the installer to complete preview 2.

After all this I was finally able to complete the tutorial.

Thank you for the help.

natemcmaster commented 8 years ago

Thanks for sharing your fix @KCGCJohnJones. Marking as "closed-external" as the issue appears to have been caused by using an old version of .NET Core CLI.