我已经成功运行了'HelloWeb'使用以下命令从Windows 8.1上的Kestrel服务器获取ASP.NET5 GitHub存储库中的示例:
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
最终更新
问题是红隼包版本。无论出于何种原因,Nuget经理只建议我使用Kestrel beta 4,而所有其他软件包都安装为beta 6.在project.json中手动将Kestrel设置为beta 6后,一切正常。我接受了Gerald Davies的回答,因为他给了我正确的方向。
答案 0 :(得分:3)
错误似乎表明正在使用的运行时,应用程序所期望的运行时以及可能的特定运行时可用的依赖项之间不匹配。
首先使用dnvm list
并验证正在使用的运行时(活动)。请在更新中发布。如果错误的运行时设置为活动,则需要使用dnvm use
进行更改。还要将其与global.json中的值进行比较。
您可能需要恢复依赖项。如果VS中的构建使用与dnvm设置为活动的运行时不同的运行时,则会发生这种情况。您可以按dnu restore
强制执行依赖关系恢复。
`dnu恢复'总是需要,但VS有时会通过自动执行它来隐藏它,因为依赖关系会发生变化,但仅限于VS正在执行的当前运行时。记住依赖关系可能因运行时而异。
由于VS使用global.json来确定执行哪个dnx(版本,运行时和体系结构),但在命令行上除非明确指出dnx / dnu使用" active&#34,否则这很复杂;运行时由dnvm设置。从技术上讲,dnvm只设置特定运行时的路径,因此在使用execute dnx或dnu时,您运行的是特定的(版本,运行时和体系结构),具体取决于路径。
关键是VS执行的dnx和命令行上执行的dnx不一定相同。改变"目标"在VS(global.json)或dnvm(使用dnvm)中,不会自动更新另一个。
因此,例如VS可以自动恢复非核心clr x86 dnx的beta4版本的依赖关系,但是由于路径(由dnvm设置)在命令行上执行时,您正在执行针对beta6版本的核心clr x64 。如果这些依赖项尚未恢复,那么您将收到错误。
答案 1 :(得分:1)
要查找异常的真正原因,可以使用dnx的--debug
开关调试此错误。尝试:
dnx --debug . kestrel
然后,您可以使用Visual Studio附加到dnx.exe并查看确切的异常并检索它的LoaderExceptions
属性。我有similar problems,两者都是由运行时不匹配和源代码错误引起的。