-
-
Notifications
You must be signed in to change notification settings - Fork 835
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
[4.9.3] OutputCacheAttribute causing issues #1013
Comments
Hi @xyanide, are you able to provide a simple project that recreates this? Just to speed up the investigation. Thanks. |
I haven't been able to pinpoint exactly where the issue lies, but have narrowed it down a bit:
Furthermore I created a test project but wasn't able to reproduce the issue there yet. The source project is fairly large so hard to identify where it might go wrong. |
OK @xyanide, I think I've figured out what's going on. Unless I'm mistaken, do you have a registration somewhere of a custom ObjectCache implementation? Something like:
With that, I get a recreate of your issue. What is happening is that Autofac is attempting to inject a dependency onto a static property, specifically ChildActionCache. It tries to create a delegate for the property's setter, and fails because it's not an instance method (static properties have static setter methods). I actually think Autofac has always injected that dependency, the change in 4.9.3 is that a delegate is created for fast subsequent setting of the property, which is where everything falls down. Personally, it feels a bit weird that Autofac would be willing to inject service instances onto static properties. If we do prevent static properties from being injected (which feels like the right behaviour), I fear it might count as a breaking change...from what I can tell, the only way to get a singleton ObjectCache implementation injected into OutputCacheAttribute is through that static property. Other usecases may also be accidentally be relying on this sort of behaviour. @tillig or @alexmg, does Autofac need to be able to inject onto static properties? If yes, then I can update MakeFastPropertySetter to handle the static property, but if no, then I'll just filter out static properties from the list of potential injection properties. |
No, I don't think static properties are injectable. Too many shoot-yourself-in-the-foot situations where something like a per-request value could be set on a static thing. |
I agree that it would lead to much shooting of feet, but prior to 4.9.3, Autofac's AutowiringPropertyInjector certainly seems to do precisely that. The OutputCacheAttribute does get an Autofac service injected onto its static ChildActionCache property. Assuming we're happy to put in this potentially breaking change, I guess it's one for 5.0? Currently in 4.9.4 anyone using static property injection with the reflection activator will be getting this exception. |
5.0 works for me. |
Ok, I'll get a PR sorted. |
You are correct, we are using a custom objectcache implementation, thanks for digging into it! |
There is no date for 5.0 at this time. |
@xyanide, just a note; once this change is available, the OutputCache attribute won't be populated with your custom ObjectCache. Were you relying on this behaviour? If so you'll need to initialise the |
After updating to 4.9.3 (from 4.9.2) i'm getting the following error on controller actions with the output cache attribute:
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
The error thrown is:
Reverting to 4.9.2 fixes the issue.
My autofac dependencies are:
id="Autofac" version="4.9.3"
id="Autofac.Mvc5" version="4.0.2"
id="Autofac.Mvc5.Owin" version="4.0.1"
id="Autofac.Owin" version="4.2.0"
.NET 4.7.2
The text was updated successfully, but these errors were encountered: