2015-11-26 32 views
3

我正在使用VS2015將ASP.NET 5應用程序部署到Azure。在成功部署並在瀏覽器中打開我的網站後,我收到錯誤:ASP.NET 5/Azure錯誤:FileNotFoundException:無法加載文件或程序集System.Data.SqlClient

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' 解決方案名爲「可怕的黑客」然後爲我工作。 :)

你有什麼想法可能會導致這個問題,以及如何解決它?

這裏是我的web應用程序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文件中看到的那樣。我可以確認包「System.Data.SqlClient」:「4.0.0-beta-23516」位於我的[approot] \ packages文件夾中。包文件夾在我的本地計算機上看起來完全如此。我已經嘗試在新創建的Web App上進行部署,以避免由於舊版本引起的任何問題。錯誤仍然是一樣的。

+0

這可能是最清晰的可執行文件m –

+0

您可以發佈您的project.json文件的內容嗎? – MrDustpan

回答

-1

在項目設置System.Data.SqlClient的本地副本屬性設置爲true,然後再試一次部署Web應用程序...

這顯然是缺少Web應用程序

+0

謝謝你的回答。我沒有提及「System.Data.SqlClient」。也許它是由另一個可靠的引用(我不知道如何找出)。此外,我無法找到「本地副本」屬性(即在ASP.NET 4項目屬性中)。我相信系統會自動管理依賴項(如果在本地沒有找到,則嘗試通過nuget源下載)。 – f0rt

+0

這是關於ASP.NET 5項目,它沒有「複製本地」屬性。 – Sebazzz

1

的bin的dll我想你想將你的System.Data.SqlClient依賴出來的dependencies進入frameworks\dnxcore50\dependencies像這樣:

"frameworks": { 
    "dnx451": { }, 
    "dnxcore50": { 
     "dependencies": { 
     "System.Data.SqlClient": "4.0.0-beta-23516" 
     } 
    } 
    } 
1

我終於在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得到部署使用這些線dependenciesframeworks在IIS上工作的dependencies重要的線是"Microsoft.NETCore.Platforms": "1.0.1-beta-23516""System.Data.Common": "4.0.1-beta-23516"。 和容器的一切從frameworks

然後將發佈的目錄wwwroot,approot和日誌複製到您的IIS網站應該在的位置。在IIS中將該網站指向wwwroot目錄。

0

我有我在Asp.net5 + MVC6面臨的同樣的問題。爲了在不使用實體框架的情況下從數據庫檢索數據,我使用了System.Data.SqlClientSystem.Data.Common。仍然有一個錯誤FileNotFoundException

之後,我刪除那些project.json和下載的軟件包:

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

在所有SQL語句的基本庫都包括在內。所以這個問題解決了。

0

這裏發生的情況是,它始終使用mscorelib和System.Data.Sqlclient都發生衝突。所以同時它將使用框架庫。你可以有一個解決方案,這是刪除dnxcore50從框架選項project.json文件。並從命令提示符恢復dnu。

相關問題