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” } –