ASP.NET 5 / Azure error: FileNotFoundException: Could not load file or assembly System.Data.SqlClient

asp.net-core azure entity-framework-core

Question

I'm deploying ASP.NET 5 application to Azure using VS2015. After successful deploy and opening my site in the browser I'm getting the error:

FileNotFoundException: Could not load file or assembly 'System.Data.SqlClient, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. The assembly is not directly referenced in my project. It is indirect dependency via EntityFramework.MicrosoftSqlServer assembly.

I had similar issue using ASP.NET 4 explained here: Error: No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient' The solution named "the terrible hack" worked for me then. :)

Do you have any ideas what might be causing the problem and how to fix it?

Here is the content of my web app project.json:

{
    "userSecretsId": "aspnet5-MyProject.Web-<A guid goes here>",
    "version": "1.0.0-*",
    "compilationOptions": {
        "emitEntryPoint": true
    },

    "dependencies": {
        "EntityFramework.Commands": "7.0.0-rc1-final",
        "EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final",
        "Microsoft.AspNet.Authentication.Cookies": "1.0.0-rc1-final",
        "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-rc1-final",
        "Microsoft.AspNet.Identity.EntityFramework": "3.0.0-rc1-final",
        "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
        "Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
        "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-rc1-final",
        "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
        "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
        "Microsoft.AspNet.Tooling.Razor": "1.0.0-rc1-final",
        "Microsoft.Extensions.CodeGenerators.Mvc": "1.0.0-rc1-final",
        "Microsoft.Extensions.Configuration.FileProviderExtensions": "1.0.0-rc1-final",
        "Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final",
        "Microsoft.Extensions.Configuration.UserSecrets": "1.0.0-rc1-final",
        "Microsoft.Extensions.Logging": "1.0.0-rc1-final",
        "Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
        "Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final",
        "Microsoft.Framework.CommandLineUtils.Sources": "1.0.0-beta5",
        "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-rc1-final",
        "MyProject.Data": "1.0.0-*",
        "System.Data.SqlClient": "4.0.0-beta-23516" <-- I've tried with this explicit dependency here
     },

     "commands": {
        "web": "Microsoft.AspNet.Server.Kestrel",
        "ef": "EntityFramework.Commands"
     },

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

     "exclude": [
        "wwwroot",
        "node_modules"
     ],
     "publishExclude": [
         "**.user",
         "**.vspscc"
     ],
     "scripts": {
        "prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ]
      }
}

and the project.json of the MyProject.Data project that MyProject.Web is depending on:

{
  "version": "1.0.0-*",
  "description": "MyProject.Data Class Library",
  "authors": [ "f012rt" ],
  "tags": [ "" ],
  "projectUrl": "",
  "licenseUrl": "",
  "frameworks": {
    "dnxcore50": {
      "dependencies": {
        "Microsoft.CSharp": "4.0.1-beta-23516",
        "System.Collections": "4.0.11-beta-23516",
        "System.Linq": "4.0.1-beta-23516",
        "System.Runtime": "4.0.21-beta-23516",
        "System.Threading": "4.0.11-beta-23516"
      }
    }
  },
  "commands": {
    "ef": "EntityFramework.Commands"
  },
  "dependencies": {
    "EntityFramework.Commands": "7.0.0-rc1-final",
    "EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final",
    "EntityFramework.Core": "7.0.0-rc1-final",
    "Microsoft.AspNet.Identity.EntityFramework": "3.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final",
    "System.Runtime.Serialization.Primitives": "4.1.0-beta-23516",
    "System.Data.SqlClient": "4.0.0-beta-23516" <-- I've tried with this explicit dependency here
  }
}

I've tried with explicitly specifying the missing dependency as you can see from my project.json files. I can confirm that the package "System.Data.SqlClient": "4.0.0-beta-23516" is in my [approot]\packages folder. The package folder looks exactly as this on my local computer. I've tried the deployment on a newly created Web App to avoid anything caused by old deplyments. The error is still the same.

Popular Answer

I finally managed to get a deployment working on IIS using these lines for dependencies and frameworks in config.json

"dependencies": {
    "Microsoft.NETCore.Platforms": "1.0.1-beta-23516",
    "Microsoft.NETCore.Targets.DNXCore": "5.0.0-beta-23516",
    "Microsoft.AspNet.Diagnostics": "1.0.0-rc1-final",
    "Microsoft.AspNet.Hosting": "1.0.0-rc1-final",
    "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
    "Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
    "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-rc1-final",
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
    "Microsoft.AspNet.Session": "1.0.0-rc1-final",
    "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
    "Microsoft.AspNet.Tooling.Razor": "1.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
    "Microsoft.Extensions.PlatformAbstractions": "1.0.0-rc1-final",
    "System.Runtime.Serialization.Primitives": "4.1.0-beta-23516",
    "System.Data.Common": "4.0.1-beta-23516"
  },
  "frameworks": {
    "dnxcore50": {
      "dependencies": {
        "System.Data.SqlClient": "4.0.0-beta-23109",
        "System.Data.SqlClient.sni-x64": "4.0.0-beta-23019",
        "runtime.win7-x64.System.Data.SqlClient.sni": "4.0.0-beta-23516"
      } }
  }

IIRC the important lines in dependencies are "Microsoft.NETCore.Platforms": "1.0.1-beta-23516" and "System.Data.Common": "4.0.1-beta-23516". And everything from the frameworks container.

Then copy the published directories wwwroot,approot and logs to the location where your IIS websites should be. In IIS point the website to the wwwroot dir.




Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why