3

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.

Community
  • 1
  • 1
f0rt
  • 1,801
  • 3
  • 17
  • 30

6 Answers6

1

I think you want to move your System.Data.SqlClient dependency out of dependencies and into frameworks\dnxcore50\dependencies like so:

"frameworks": {
    "dnx451": { },
    "dnxcore50": {
      "dependencies": {
        "System.Data.SqlClient": "4.0.0-beta-23516"
      }
     }
  }
MrDustpan
  • 5,508
  • 6
  • 34
  • 39
1

It appears to be dnx/dnu issue and they're working on it: https://github.com/aspnet/EntityFramework/issues/3637

f0rt
  • 1,801
  • 3
  • 17
  • 30
1

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.

fhus
  • 51
  • 2
0

I have the same problem which I faced in Asp.net5 + MVC6. In that for retrieving the data from database without using entityframework I was using System.Data.SqlClient and System.Data.Common. Still there was an error of FileNotFoundException.

After that I removed those from project.json and downloaded the package:

"EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final"

In that all the basic libraries of Sql are included. So this problem was solved.

Artem Mostyaev
  • 3,874
  • 10
  • 53
  • 60
Pankti Shah
  • 189
  • 1
  • 6
0

The scenario happening here is, its always go for using mscorelib and System.Data.Sqlclient both and got conflict. so at the same time it is going to use framework libraries. You can have one solution to this is remove dnxcore50 from frameworks option in the project.json file. and restore dnu from command prompt.

InspireMe
  • 119
  • 1
  • 1
  • 5
-1

In your project set the System.Data.SqlClient Local Copy property to true and try deploying the web app again...

It is obviously missing the dll in the bin of the web app

Aram
  • 5,537
  • 2
  • 30
  • 41
  • Thank you for the answer. I don't have reference to "System.Data.SqlClient". Maybe it is referenced by another assebly (I don't know which and don't know how to find out). Also I can't find "local copy" property (that was in the ASP.NET 4 projects properties). I believe that the system manages the dependency automatically (tries to download via nuget sources if they are not found locally). – f0rt Nov 27 '15 at 20:15
  • This is about ASP.NET 5 project which don't have and 'Copy Local' property. – Sebazzz Nov 28 '15 at 22:29