3

我已經基於ASP.NET 5 beta 8 Visual Studio模板創建了一個簡單的ASP.NET 5項目。在納米服務器上運行ASP.NET 5會引發「無法加載DLL'kernel32'」

我已經發布了使用此命令

dnu publish <path to project.json> --out <path to publish folder> --configuration Release --runtime dnx-coreclr-win-x64.1.0.0-beta8 --wwwroot-out "wwwroot" --no-source 

我跑納米服務器上web.cmd後,我收到此錯誤的項目:

.\web.cmd : System.DllNotFoundException: Unable to load DLL 'kernel32': The specified module could not be found. (Exception from HRESULT: 
0x8007007E) 
    + CategoryInfo   : NotSpecified: (System.DllNotFo...LT: 0x8007007E):String) [], RemoteException 
    + FullyQualifiedErrorId : NativeCommandError 

    at Microsoft.AspNet.Server.Kestrel.Networking.PlatformApis.WindowsApis.LoadLibrary(String dllToLoad) 
    at Micros 
oft.AspNet.Server.Kestrel.Networking.Libuv.Load(String dllToLoad) 
    at Microsoft.AspNet.Server.Kestrel.ServerFactory.Start(IFeatureCollection serverFeatures, Func`2 application) 
    at Microsoft.AspNet.Hosting.Internal.HostingEngine.Start() 
    at Microsoft.AspNet.Hosting.Program.Main(String[] args) 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
    at Microsoft.Dnx.Runtime.Common.EntryPointExecutor.Execute(Assembly assembly, String[] args, IServiceProvider serviceProvider) 
    at Microsoft.Dnx.ApplicationHost.Program.ExecuteMain(DefaultHost host, String applicationName, String[] args) 
    at Microsoft.Dnx.ApplicationHost.Program.Main(String[] args) 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
    at Microsoft.Dnx.Runtime.Common.EntryPointExecutor.Execute(Assembly assembly, String[] args, IServiceProvider serviceProvider) 
    at Microsoft.Dnx.Host.Bootstrapper.RunAsync(List`1 args, IRuntimeEnvironment env, String appBase, FrameworkName targetFramework) 
    at Microsoft.Dnx.Host.RuntimeBootstrapper.ExecuteAsync(String[] args, BootstrapperContext bootstrapperContext) 
    at Microsoft.Dnx.Host.RuntimeBootstrapper.Execute(String[] args, BootstrapperContext bootstrapperContext) 

同樣的命令不會拋出這個錯誤在Windows 10上運行。該應用程序在Windows 10上正常工作。

+0

您需要安裝反向代理... – Pawel

+0

可以請你這加作爲一個答案,所以我可以將其標記 –

回答

1

納米服務器沒有kernel32.dll和advapi32.dll,所以沒有鏈接到默認庫的代碼將無法工作。您需要將您的代碼與onecore.lib鏈接或安裝反向轉發器。反向轉發器將調用kernel32.dll/advapi32.dll API重定向到Nano Server上可用的對應程序。在某些OneCore系統上(例如Raspberry Pi 2上的Win10 IoT Core),默認情況下會安裝反向轉發器。 Nano服務器的情況並非如此,因爲它的目標是儘可能小。因此,如果你需要他們,需要手動安裝反向代理。 要涉及這Asp.Net 5 - 既使用HTTP處理程序平臺和紅隼(或更具體libuv)是針對默認庫聯繫,因此對納米運行Asp.Net 5,除非你使用WebListener應該很好地工作,你需要代理沒有貨代。

0

假設

你提到這個應用程序在Windows上工作正常。你如何在Windows上運行它?您很有可能使用dnx451而不是dnxcore50(CoreCLR)作爲您的目標平臺。

這是一個問題,因爲您正在爲CoreCLR發佈。 (--runtime dnx-coreclr-win-x64.1.0.0-beta8),並且在本地運行時很有可能使用完整的.NET框架。

它可以在Windows 10上使用CoreCLR嗎?

這是我會做的:嘗試使用dnx運行Developer Command Prompt for Visual Studio 2015中的web應用程序。使用dnvm

  1. 切換到.NET的CoreCLR版本:

    dnvm use 1.0.0-beta-8 -r coreclr 
    
  2. 恢復包

    dnu restore 
    
  3. 運行

    dnx web 
    

如果失敗,我們知道是什麼問題。如果成功,Nano可能不會提供您的代碼嘗試執行的本機Windows API。如果是這種情況,你必須識別導致這種情況的代碼並使用別的東西。

如何只針對CoreCLR在Visual Studio

您可以刪除dnx451目標的project.json使Visual Studio是被迫使用dnxcore50(CoreCLR)版本。理想情況下,我們希望運行我們發佈的完全相同的版本/環境。

+0

感謝您的回答。但我只是針對coreclr。這是我的project.json 「框架」:{ 「dnxcore50」:{}} , 這global.json 「SDK」:{ 「版本」: 「1.0.0-beta8」, 「結構」: 「64」, 「運行時間」: 「coreclr」 } –

相關問題