ASP.NET 5 / Azure錯誤:FileNotFoundException:無法加載文件或程序集System.Data.SqlClient

asp.net-core azure 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時出現類似的問題: 錯誤:找不到具有不變名稱'System.Data.SqlClient'的ADO.NET提供程序的實體框架提供程序名為“可怕的黑客”的解決方案對我有用。 :)

您有什麼想法可能導致問題以及如何解決問題嗎?

這是我的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" ]
      }
}

以及MyProject.Web依賴的MyProject.Data項目的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" ]
      }
}

我已經嘗試過顯式指定缺少的依賴項,你可以從我的project.json文件中看到。我可以確認包“System.Data.SqlClient”:“4.0.0-beta-23516”在我的[approot] \ packages文件夾中。包文件夾在我的本地計算機上看起來與此完全相同。我已嘗試在新創建的Web應用程序上進行部署,以避免由舊的deplyments引起的任何事情。錯誤仍然相同。

熱門答案

我終於設法使用這些代碼在config.json使用這些dependenciesframeworks在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目錄。




許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow
這個KB合法嗎? 是的,了解原因
許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow
這個KB合法嗎? 是的,了解原因