-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HttpContext.Current is null exception #15
Comments
The static ...however the stack-trace doesn't show any signs of it being an async continunation or background-thread, but it's coming from the build-manager instead, hmm. Can you please post your actual (and entire) Thank you. |
@jrmoreno1 any update? Thanks! |
This was a a quick exploration on my own time with a work project and for consistency we are going to be using AutoFaq, so I no longer have a project in the exact state I had at the time. I think you are right about it being a threading issue, possibly a conflict with some Owin libraries we are using. I will look into it some more when I can and get back to you. |
Sure - I'll leave this issue open until you're able to find out more information. Though my money is on something in your project's code that causes an async continuation on the wrong thread or code that tries to use ASP.NET from a non-request thread - possibly something in |
I haven't forgotten about this, I have actually made some progress: I now have an empty project that exhibits the behavior, which I have been able to move over into a local git repository. I have an empty global.asax file, and an empty ConfigureServices method. It'll probably be a while before I can reduce it down to something a bit more concrete, but I'm fairly sure I'll get there eventually. |
@jrmoreno1 Boop? |
I have the same issue with the same stacktrace. My project was converted from Website project to Web application project type I can't reproduce it on freshly created project though. And I can't share full sources of the project too. But I can do some research for you if you know where to dig. My DI setup code, as you can see error occurs even for container without registered types.
|
Guess it has something to do with dynamic compilation process Website project type has. Web application might do the same thing since when I removed most of the folders from my project, HttpContext.Current was not null anymore, but getting another error.
|
A note on this in case what I am seeing matches with the source of the above reported issue. I was receiving the same error with the same call stack. In order to attempt to diagnose the issue, I added a class which wraps the IServiceProvider registered by this nuget package on HttpRuntime.WebObjectActivator. i.e. after the call to the Build() method (chained from the ApplicationDependencyInjectionBuilder)
The above allowed me to identify that the type which was failing to be resolved (repeatedly) was: System.Data.Services.BuildProvider.DataServiceBuildProvider According to the MSDN documentation, this is used for WCF Data Services: I have attempted to find a WCF or WCF data services reference in our application, but have been unable to find one. However, ours is an extremely large application, with many indirect references, so it is possible we do have some that I have not been able to identify. Regardless, I found that if I altered the above catch exception handler, to do the following:
This resulted in our website being able to execute successfully without this resolution failure causing the app to fail to start. I realize that elsewhere in this project/repository there is information on adapting WCF to be dependency injection compatible. I will take a look at that next, to see if any suggested WCF changes might also fix this issue (and hopefully more correctly than the hacked up solution I have presently). Anyway, I thought I'd post the above in case it does turn out to be a common source of the above issue. One thing I would suggest @daiplusplus is that it might be worth including the typename of the type which fails to be resolved on all resolution failures - that might help narrow down the source of, or type of, resolution failures which occur. |
Ok, I found the issue. At least for my occurrence of the above issue.... It was kind of driving me nuts that when running tests, my previously shown code was logging that the DI container was successfully creating and returning other build provider classes. I finally, downloaded the source code for the nuget package, and added the project to my solution so that I could debug in and see what was going on, and why it was failing to create the DataServiceBuildProvider build provider type, and yet was succeeding on all the other build providers (e.g. PageBuildProvider, ResXBuildProvider, SourceFileBuildProvider, UserControlBuildProvider etc. etc.). The reason it succeeds on the other build providers is because the default DefaultDependencyInjectionOverrideService has a list of namespaces which will be excluded, and instead the system will use AspNetDependencyInjection.Internal.ActivatorServiceProvider.Instance to generate the requested build provider. Here's the thing... This is the list of namespaces which are ignored by default:
The vast majority of the build provider classes ARE in the System.Web namespace. Actually they are in the System.Web.Compilation namespace - but that of course will match the "System.Web.*" filter. But the DataServiceBuildProvider provider is NOT in this namespace. It is in the namespace "System.Data.Services.BuildProvider", which does not match any of the default excluded namespaces. Why does this not always cause a failure?? The reason for that is that the code in System.Web appears to only attempt to instantiate the DataServiceBuildProvider build provider when you have a "App_WebReferences" folder in your website. And note, it does not appear to even matter if you have any files in this folder - just the presence of this folder will cause the System.Web code to attempt to create a DataServiceBuildProvider via HttpRuntime.CreatePublicInstanceByWebObjectActivator(type). So, this combination of factors - the DataServiceBuildProvider not being in an excluded namespace, and the presence of a "App_WebReferences" folder in your website will trigger the issue. I did also take a look with a decompiler at a known list of subclasses of the "BuildProvider" base class, and there is ONE more (in the list that could be found from the assemblys I had loaded) build provider which would not match the default list of excluded namespaces - which is "System.Xaml.Hosting.XamlBuildProvider" - so if this build provider is attempted to be instantiated it could also cause the same issue on startup. Anyways, there is an easy fix without needing any change in the current published nuget package...: In your application, where you are registering your services, add the following line:
This AddDefaultDependencyInjectionOverrideService extends the excluded namespaces to include the namespace which will result in the desired exclusion of the DataServiceBuildProvider - so that it too will be successfully created by the system. |
I am getting an exception after calling the AppplicationDependencyInjectionBuilder.Build, and I can't figure out what I have setup wrong. I trimmed the ConfigurationServices method down to nothing (just a return), but that doesn't help.
The text was updated successfully, but these errors were encountered: