Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
[4.9.3] OutputCacheAttribute causing issues #1013
After updating to 4.9.3 (from 4.9.2) i'm getting the following error on controller actions with the output cache attribute:
The error thrown is:
Reverting to 4.9.2 fixes the issue.
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.
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.