找不到ASP.NET Core 1.0 EF7 System.Data.SqlClient

asp.net-core docker entity-framework-core

今天我嘗試將我的asp.net核心1.0項目部署到我的服務器上。我在Visual Studio中創建了一個FileSystemDeploy並將其傳輸到我的服務器。我想在Docker容器中運行該網站。我正在使用microsoft / aspnet:1.0.0-rc1-update1-coreclr

僅僅為了測試我使用以下命令啟動了docker鏡像:

docker run -it --name JamesWeb -v ~/James/James.Web:/root --net=host microsoft/aspnet:1.0.0-rc1-update1-coreclr

然後我做了一個按預期工作的dnu恢復 。之後我用dnu web啟動了應用程序。到目前為止控制台中沒有錯誤。當我打開網站時,起始頁面也正常工作,但是當我嘗試轉到我正在使用DatabaseContext的頁面時,我收到一條錯誤消息:

fail: Microsoft.Data.Entity.Query.Internal.QueryCompiler[1]
  An exception occurred in the database while iterating the results of a query.
  System.IO.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.

  File name: 'System.Data.SqlClient, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' ---> System.IO.FileNotFoundException: Could not load the specified file.
  File name: 'System.Data.SqlClient'
     at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyName(AssemblyName assemblyName)
     at System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)
     at Microsoft.Data.Entity.Storage.Internal.SqlServerConnection.CreateDbConnection()
     at Microsoft.Data.Entity.Internal.LazyRef`1.get_Value()
     at Microsoft.Data.Entity.Storage.RelationalConnection.Open()
     at Microsoft.Data.Entity.Query.Internal.QueryingEnumerable.Enumerator.MoveNext()
     at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()
     at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
     at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
     at lambda_method(Closure , QueryContext )
     at Microsoft.Data.Entity.Query.Internal.QueryCompiler.<>c__DisplayClass18_1`1.<CompileQuery>b__1(QueryContext qc)

我正在為DBContext使用以下連接字符串

"Server=(localdb)\\mssqllocaldb;Database=James-Web;Trusted_Connection=True;MultipleActiveResultSets=true"

通過運行dnx ef數據庫更新輸出以應用遷移:

File name: 'System.Data.SqlClient, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' ---> System.IO.FileNotFoundException: Could not load the specified file.
File name: 'System.Data.SqlClient'
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyName(AssemblyName assemblyName)
   at System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)
   at Microsoft.Data.Entity.Storage.Internal.SqlServerConnection.CreateDbConnection()
   at Microsoft.Data.Entity.Internal.LazyRef`1.get_Value()
   at Microsoft.Data.Entity.Migrations.Internal.Migrator.Migrate(String targetMigration)
   at Microsoft.Data.Entity.Design.MigrationsOperations.UpdateDatabase(String targetMigration, String contextType)
   at Microsoft.Data.Entity.Commands.Program.Executor.Execute(Action action)
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.

project.json:

{
  "userSecretsId": "aspnet5-James.Web-9bb7a5b0-c3f5-4309-984f-5c6057584cb5",
  "webroot": "wwwroot",
  "version": "1.0.0-*",
  "compilationOptions": {
    "emitEntryPoint": true
  },

  "dependencies": {
    "EntityFramework.Commands": "7.0.0-rc1-final",
    "EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final",
    "Microsoft.ApplicationInsights.AspNet": "1.0.0-rc1",
    "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.VisualStudio.Web.BrowserLink.Loader": "14.0.0-rc1-final",
    "Microsoft.AspNet.Authentication.Facebook": "1.0.0-rc1-final",
    "Microsoft.AspNet.Authentication.Google": "1.0.0-rc1-final"
  },

  "frameworks": {
    "dnx451": {
      "frameworkAssemblies": {
        "System.IO.Compression": "4.0.0.0",
        "System.IO.Compression.FileSystem": "4.0.0.0"
      }
    },
    "dnxcore50": {
      "dependencies": {
        "System.IO.Compression.ZipFile": "4.0.1-beta-23516"
      }
    }
  },

  "commands": {
    "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel --server.urls http://localhost:5000",
    "ef": "EntityFramework.Commands"
  },

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

一般承認的答案

這是RC1中DNX準備發布應用程序的方式中的已知問題。據我所知,RC1沒有解決方法。這應該在RC2中修復。請參閱https://github.com/aspnet/dnx/issues/3316https://github.com/dotnet/cli/issues/881



Related

許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow
許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow