Hosting icon indicating copy to clipboard operation
Hosting copied to clipboard

Error in HostingEngine.Start

Open easyt opened this issue 11 years ago • 3 comments

After updating to Beta8, I get an error when I call HostingEngine.Start. I am hosting ASP.NET 5 using DNX in a Windows service. This has worked up until Beta8. The issue is critical for us. The failure is ultimately in DNX when it tries to resolve IRuntimeEnvironment. The problem is not that the service is not registered, but the fact that CallContextServiceLocator.Locator.ServiceProvider is returning null. This happens because the implementation is using CallContext.LogicalGetData. Since DNX is bootstrapped on the main thread, this is returning null when accessed from the thread that calls ServiceBase.OnStart.

System.InvalidOperationException: Failed to resolve IRuntimeEnvironment at Microsoft.Dnx.Runtime.RuntimeEnvironmentHelper.GetRuntimeEnvironment() at Microsoft.Dnx.Runtime.RuntimeEnvironmentHelper.<>c.<.cctor>b__10_2() at System.Lazy1.CreateValue() at System.Lazy1.LazyInitValue() at System.Lazy1.get_Value() at Microsoft.Dnx.Runtime.RuntimeEnvironmentHelper.<>c.<.cctor>b__10_0() at System.Lazy1.CreateValue() at System.Lazy1.LazyInitValue() at System.Lazy1.get_Value() at Microsoft.Dnx.Runtime.FrameworkReferenceResolver.GetReferenceAssembliesPath() at Microsoft.Dnx.Runtime.FrameworkReferenceResolver.GetFrameworkInformation(FrameworkName targetFramework) at System.Collections.Generic.DictionaryExtensions.GetOrAdd[TKey,TValue](IDictionary2 dictionary, TKey key, Func2 factory) at Microsoft.Dnx.Runtime.FrameworkReferenceResolver.TryGetAssembly(String name, FrameworkName targetFramework, String& path, Version& version) at Microsoft.Dnx.Runtime.ReferenceAssemblyDependencyResolver.GetDescription(LibraryRange libraryRange, FrameworkName targetFramework) at Microsoft.Dnx.Runtime.ApplicationHostContext.Initialize(ApplicationHostContext context) at Microsoft.Dnx.ApplicationHost.RuntimeLibraryManager.<>c__DisplayClass1_0.<.ctor>b__0() at System.Lazy1.CreateValue() at System.Lazy1.LazyInitValue() at System.Lazy1.get_Value() at Microsoft.Dnx.ApplicationHost.RuntimeLibraryManager.GetLibrary(String name) at Microsoft.AspNet.Server.Kestrel.KestrelEngine..ctor(ILibraryManager libraryManager, ServiceContext context) at Microsoft.AspNet.Server.Kestrel.ServerFactory.Start(IFeatureCollection serverFeatures, Func2 application) at Microsoft.AspNet.Hosting.Internal.HostingEngine.Start() at MyDnxService.Program.OnStart(String[] args)

I know you plan to changing CallContextServiceLocator. Will this be fixed, if so when? This is a huge dealbreaker and a loss of a lot of development time if this is not fixed.

Here is a link to the a paired down repo with the issue. The code in the repo works. If you upgrade the application to beta8 (in project.json) and reinstall the service, you will see the error.

Please let me know if you need more information.

easyt avatar Nov 10 '15 19:11 easyt

Looks similar to https://github.com/aspnet/Mvc/issues/3296.

Also https://github.com/aspnet/Hosting/issues/30#issuecomment-154993775

Tratcher avatar Nov 10 '15 20:11 Tratcher

Exactly. I didn't see that post. David's workaround should fix it, but hopefully there will be something done to alleviate the need for the workaround.

Thanks.

easyt avatar Nov 10 '15 20:11 easyt

This error shouldn't happen in rc1

davidfowl avatar Nov 23 '15 04:11 davidfowl