ASP.NET 5 / Azure错误:FileNotFoundException:无法加载文件或程序集System.Data.SqlClient

时间:2015-11-26 21:50:26

标签: azure asp.net-core entity-framework-core

我使用VS2015将ASP.NET 5应用程序部署到Azure。在浏览器中成功部署并打开我的网站后,我收到错误:

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. 我的项目中没有直接引用该程序集。它是通过EntityFramework.MicrosoftSqlServer程序集的间接依赖。

我使用ASP.NET 4解决了类似的问题:Error: No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient' 解决方案名为"可怕的黑客"那时为我工作。 :)

您是否有任何想法可能导致问题以及如何解决问题?

以下是我的网络应用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" ]
      }
}

以及MyProject.Web依赖的MyProject.Data项目的project.json:

{
  "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
  }
}

我已尝试过显式指定缺少的依赖项,您可以从我的project.json文件中看到。我可以确认包&#34; System.Data.SqlClient&#34;:&#34; 4.0.0-beta-23516&#34;在我的[approot] \ packages文件夹中。包文件夹在我的本地计算机上看起来与此完全相同。我已尝试在新创建的Web应用程序上进行部署,以避免由旧的deplyments引起的任何事情。错误仍然是一样的。

6 个答案:

答案 0 :(得分:1)

我认为您希望将print(dict(re.findall(r"(SECTION\s+\d+)\.\s*([^S]*(?:S(?!ECTION\s+\d+\.)[^S]*)‌​*)", text))) 依赖关系移出System.Data.SqlClient并转移到dependencies,如下所示:

frameworks\dnxcore50\dependencies

答案 1 :(得分:1)

它似乎是dnx / dnu问题,他们正在研究它:https://github.com/aspnet/EntityFramework/issues/3637

答案 2 :(得分:1)

我终于设法使用dependencies中的frameworksconfig.json这些行在IIS上进行部署工作

"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 dependencies中的重要行是"Microsoft.NETCore.Platforms": "1.0.1-beta-23516""System.Data.Common": "4.0.1-beta-23516"。 以及frameworks容器中的所有内容。

然后将发布的目录wwwroot,approot和logs复制到IIS网站所在的位置。在IIS中将网站指向wwwroot dir。

答案 3 :(得分:0)

我遇到了与Asp.net5 + MVC6相同的问题。为了在不使用entityframework的情况下从数据库中检索数据,我使用的是System.Data.SqlClientSystem.Data.Common。仍然存在FileNotFoundException错误。

之后我从project.json删除了那些并下载了包:

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

因为包含了所有Sql的基本库。所以这个问题就解决了。

答案 4 :(得分:0)

这里发生的情况是,它总是使用 mscorelib 和System.Data.Sqlclient两者并且发生冲突。所以同时它将使用框架库。你可以有一个解决方案是从 project.json 文件中的frameworks选项中删除 dnxcore50 。并从命令提示符恢复dnu。

答案 5 :(得分:-1)

在您的项目中将System.Data.SqlClient Local Copy属性设置为true并尝试再次部署Web应用程序...

显然缺少网络应用程序bin中的dll