Run ASP.NET5 Web Application with Kestrel Server on Windows

I am successfully running the "HelloWeb" sample from the ASP.NET5 GETHUB repository with Kestrel server on Windows 8.1 with:

dnx. Kestrel

Now I want to run my application with a kestrel. I tried this from Visual Studio 2015RC and with multiple modes of operation using dnx directly. The result is always:

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)

      

Is there a way to find which types cannot be loaded?

Update

Here is the .json project

{
  "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"
  ]

}

      

I tried to start it with Kestrel from VS and install Kestrel to use the following runtime, which resulted in error messages in VS.

Runtime: 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

      

Final update

The problem was the version of the kestrel package. For some reason, the Nuget manager only offered me the beta version of Kestrel 4 and all other packages were installed as beta 6. After manually setting Kestrel to beta 6 in project.json, everything worked. I accept Gerald Davis' answer when he gave me the right direction.

+3


source to share


2 answers


The error would indicate a mismatch between the runtime used, the runtime expected by the application, and possibly the dependencies available for a particular runtime.

First use dnvm list

and check which runtime is in use (active). Please post this in an update. If the wrong runtime is set to active, you will need to change it using dnvm use

. Also compare this with the values ​​in global.json for your solution.

You may need to repair dependencies. This can happen if the VS build uses a different runtime than the installed dnvm. You can forcibly restore the dependency to dnu restore

.

"Dnu repair" is always necessary, but VS sometimes hides it, executing it automatically as dependencies change, but only for the current VS runtime. Remember that dependencies are runtime dependent.



This is complicated by the fact that VS uses global.json to determine which dnx to run (version, runtime and architecture), but on the command line, unless dnx / dnu is explicitly told to use the "active" runtime set by dnvm. Technically dnvm just sets the path to a specific runtime, so when you use dnx or dnu, you use a specific (version, runtime and architecture) depending on the path.

The main point is that the dnx that VS runs and the dnx that you run on the command line are not necessarily the same. Changing the "target" in VS (global.json) or in dnvm (using dnvm) does not automatically update the other.

So, for example, VS can automatically restore dependencies for a beta non-core clr x86 dnx, but because of the path (set by dnvm) when you execute on the command line you run against the beta version of the clr x64 kernel, unless those dependencies are restored , you will receive an error message.

+3


source


To find the real cause of the exception, you can debug the error using --debug

the dnx switch. Try:

dnx --debug . kestrel

      



Then you can connect to dnx.exe using Visual Studio and see the exact exception and get its property LoaderExceptions

. I had similar problems caused by runtime errors and source code errors.

+1


source







All Articles