Skip to content
This repository has been archived by the owner on Dec 19, 2018. It is now read-only.

RC1(15958): Unable to resolve service for type 'Microsoft.AspNet.Hosting.IApplicationLifetime' #434

Closed
xatabhk opened this issue Oct 21, 2015 · 10 comments
Assignees
Milestone

Comments

@xatabhk
Copy link

xatabhk commented Oct 21, 2015

Running website under IISExpress in IDE gives no detailed error; but 'dnx web' prints the following error messages:
System.InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNet.Hosting.IApplicationLifetime' while attempting to activate 'Microsoft.AspNet.Server.Kestrel.ServerFactory'.
at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.ConstructorMatcher.CreateInstance(IServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance(IServiceProvider provider, Type instanceType, Object[] parameters)
at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetServiceOrCreateInstance(IServiceProvider provider, Type type)
at Microsoft.AspNet.Hosting.Server.ServerLoader.LoadServerFactory(String assemblyName)
at Microsoft.AspNet.Hosting.Internal.HostingEngine.EnsureServer()
at Microsoft.AspNet.Hosting.Internal.HostingEngine.BuildApplication()
at Microsoft.AspNet.Hosting.Internal.HostingEngine.Start()
at Microsoft.AspNet.Hosting.Program.Main(String[] args)
at Microsoft.AspNet.Server.Kestrel.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)

@Tratcher
Copy link
Member

@davidfowl @pakrym, is this yours?

@davidfowl
Copy link
Member

@xatabhk Please provide a repro

@xatabhk
Copy link
Author

xatabhk commented Oct 24, 2015

Steps to reproduce the error:

  1. Create a simple Web App (beta8) with Wizard.
  2. Upgrade it to RC1 15958 (https://www.myget.org/F/aspnetlitedev/api/v2).
  3. dnx web

When RC1 (now 15838) from https://www.myget.org/F/aspnetvnext/api/v3/index.json used, there is no this error.

@Tratcher
Copy link
Member

Did you update to RC1 packages as well? Using RC1 DNX with beta8 packages is not supported, and it's best to pull your DNX and packages from the same feed to make sure they're in sync.

@xatabhk
Copy link
Author

xatabhk commented Oct 24, 2015

Yes. I created two new Web Apps with Wizard, one for RC1 15958 and another for RC1 15938 and wiped out all RC1 dnx runtimes and all packages before each test.

@davidfowl
Copy link
Member

@xatabhk You has a mismatch of versions. Either use * or use beta8 and it'll work either way.

@xatabhk
Copy link
Author

xatabhk commented Oct 25, 2015

It was unlikely a mismatch of versions, since I used * and restored all files starting with a clean slate by wiping out all previous versions before each test.

@yukozh
Copy link
Contributor

yukozh commented Oct 25, 2015

@xatabhk, Did you used the Microsoft.Dnx.Runtime or Microsoft.Dnx.Runtime.Infrastructure? It has been renamed to Microsoft.Extensions.PlatformAbstractions.

@Tratcher
Copy link
Member

Ok, I've found it. The IApplicationLifetime service is added here:

_applicationServiceCollection.AddInstance<IApplicationLifetime>(_applicationLifetime);

However, if there's an exception loading your startup class then it gets caught and we rebuild the app services without IApplicationLifetime:
_applicationServices = _applicationServiceCollection.BuildServiceProvider();

Workaround: Run your app under the debugger with all first-chance exceptions enabled. This will let you see the original error.

@davidfowl
Copy link
Member

Good catch!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants