【发布时间】:2015-11-26 16:23:56
【问题描述】:
我已使用 Windows 8.1 上的 Kestrel 服务器成功运行 ASP.NET5 GitHub 存储库中的“HelloWeb”示例:
dnx 。红隼
现在我想用 kestrel 运行我自己的应用程序。我从 Visual Studio 2015RC 和几个运行时直接使用 dnx 进行了尝试。结果总是:
System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the
requested types. Retrieve the LoaderExceptions property for more information.
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.RuntimeAssembly.get_DefinedTypes()
at Microsoft.AspNet.Hosting.Server.ServerLoader.LoadServerFactory(String serv
erFactoryIdentifier)
at Microsoft.AspNet.Hosting.Internal.HostingEngine.BuildApplication()
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.Framework.Runtime.Common.EntryPointExecutor.Execute(Assembly ass
embly, String[] args, IServiceProvider serviceProvider)
at Microsoft.Framework.ApplicationHost.Program.ExecuteMain(DefaultHost host,
String applicationName, String[] args)
at Microsoft.Framework.ApplicationHost.Program.Main(String[] args)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.Framework.Runtime.Common.EntryPointExecutor.Execute(Assembly ass
embly, String[] args, IServiceProvider serviceProvider)
at dnx.host.Bootstrapper.RunAsync(List`1 args, IRuntimeEnvironment env)
at dnx.host.RuntimeBootstrapper.ExecuteAsync(String[] args)
at dnx.host.RuntimeBootstrapper.Execute(String[] args)
有什么方法可以找到哪些类型无法加载?
更新
这里是 project.json
{
"webroot": "wwwroot",
"version": "1.0.0-*",
"dependencies": {
"Microsoft.AspNet.Mvc": "6.0.0-beta6-14023",
"Microsoft.AspNet.Server.IIS": "1.0.0-beta6-11864",
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta6-12245",
"Microsoft.AspNet.StaticFiles": "1.0.0-beta6-11996",
"EntityFramework.SqlServer": "7.0.0-beta6-13336",
"EntityFramework.Commands": "7.0.0-beta6-13336",
"Microsoft.Framework.ConfigurationModel.Json": "1.0.0-beta5-11337",
"Microsoft.AspNet.Identity.EntityFramework": "3.0.0-beta6-12521",
"Microsoft.AspNet.SignalR.Server": "3.0.0-beta6-12519",
"Microsoft.AspNet.Authentication.OAuthBearer": "1.0.0-beta4",
"Kestrel": "1.0.0-beta4"
},
"commands": {
"web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5000",
"kestrel": "Microsoft.AspNet.Hosting --server Kestrel --server.urls http://localhost:5004",
"ef": "EntityFramework.Commands"
},
"frameworks": {
"dnx451": { },
"dnxcore50": { }
},
"exclude": [
"wwwroot",
"node_modules",
"bower_components"
],
"publishExclude": [
"node_modules",
"bower_components",
"**.xproj",
"**.user",
"**.vspscc"
]
}
我尝试在 VS 中使用 Kestrel 启动它,并将 Kestrel 设置为使用以下运行时,这导致在 VS 中显示错误消息。
运行时:1.0.0-beta6-11921 .NET Framework x86
Exception thrown: 'System.Reflection.ReflectionTypeLoadException' in mscorlib.dll
Exception thrown: 'System.Reflection.TargetInvocationException' in mscorlib.dll
Exception thrown: 'System.Reflection.ReflectionTypeLoadException' in mscorlib.dll
Exception thrown: 'System.Reflection.ReflectionTypeLoadException' in Microsoft.Framework.ApplicationHost.dll
Exception thrown: 'System.Reflection.TargetInvocationException' in mscorlib.dll
Exception thrown: 'System.Reflection.ReflectionTypeLoadException' in mscorlib.dll
Exception thrown: 'System.Reflection.ReflectionTypeLoadException' in dnx.host.dll
最终更新
问题出在 kestrel 软件包版本上。无论出于何种原因,Nuget 经理只建议我使用 Kestrel beta 4,而所有其他软件包都安装为 beta 6。在 project.json 中手动将 Kestrel 设置为 beta 6 后,一切正常。我接受 Gerald Davies 的回答,因为他给了我正确的方向。
【问题讨论】:
-
您使用哪个运行时?运行时版本必须与依赖版本一致,我建议使用最后一个稳定版本:beta4
-
如果您在 VS 内调试时运行它,您应该能够中断异常并检查 LoaderExceptions 属性,如错误消息中所建议的那样。
-
@Igoncalves:我确实在命令行中运行了 ASP.NET5 示例,但在 VS 中有自己的应用程序。我能够按照您的建议设置断点。我将使用新结果更新我的问题...
-
"Nuget manager only suggested me Kestrel beta 4 while all other packages got installed as beta 6"@NicolasR ,Kestrel 似乎落后于 DNX 的其余部分。我刚刚遇到了同样的问题,NuGet 为 DNX beta 8 安装了 Kestrel beta 6。
标签: asp.net-core