zcz527 / autofac

Automatically exported from code.google.com/p/autofac
Other
0 stars 0 forks source link

Glimpse interferes with ExtensibleActionInvoker on MVC5 #451

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
When Glimpse is disabled, the ExtensibleActionInvoker is able to inject 
parameters into controller actions without issue. When it is enabled, injection 
fails.

This can be reproduced in the "Remember.Web" sample application in the Autofac 
solution:

* Start the application.
* Click the "Enable Glimpse" link.
* Click the button to turn Glimpse on.
* Navigate back to the home page of the demo app.
* Go to the "ExtensibleActionInvoker Integration Tests" page.
* Run the "Simple Controller Action Parameter Injection" tests.

An exception will appear; details below.

It appears that Glimpse is attempting to wrap/replace the action invoker as 
part of its debugging integration. Note the stack trace in the application 
never runs through Autofac the way it should if ExtensibleActionInvoker is in 
place.

Related: a similar issue has been reported (appended to Issue #351) where the 
AutofacFilterAttributeFilterProvider is also running into trouble, most likely 
for similar reasons.

Exception re: ExtensibleActionInvoker below:

Server Error in '/' Application.
--------------------------------------------------------------------------------

Cannot create an instance of an interface. 
  Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

 Exception Details: System.MissingMethodException: Cannot create an instance of an interface.

Source Error: 

 An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace: 

[MissingMethodException: Cannot create an instance of an interface.]
   System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
   System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +113
   System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +232
   System.Activator.CreateInstance(Type type, Boolean nonPublic) +83
   System.Activator.CreateInstance(Type type) +6
   System.Web.Mvc.DefaultModelBinder.CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType) +183
   System.Web.Mvc.DefaultModelBinder.BindComplexModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +564
   System.Web.Mvc.DefaultModelBinder.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +416
   Castle.Proxies.DefaultModelBinderProxy.BindModel_callback(ControllerContext controllerContext, ModelBindingContext bindingContext) +44
   Castle.Proxies.Invocations.DefaultModelBinder_BindModel.InvokeMethodOnTarget() +191
   Castle.DynamicProxy.AbstractInvocation.Proceed() +117
   Glimpse.Core.Extensibility.CastleInvocationToAlternateMethodContextAdapter.Proceed() +48
   Glimpse.Core.Extensibility.ExecutionTimer.Time(Action action) +195
   Glimpse.Core.Extensions.AlternateMethodContextExtensions.TryProceedWithTimer(IAlternateMethodContext context, TimerResult& timerResult) +198
   Glimpse.Core.Extensibility.AlternateMethod.NewImplementation(IAlternateMethodContext context) +45
   Glimpse.Core.Extensibility.AlternateTypeToCastleInterceptorAdapter.Intercept(IInvocation invocation) +183
   Castle.DynamicProxy.AbstractInvocation.Proceed() +483
   Castle.Proxies.DefaultModelBinderProxy.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +219
   System.Web.Mvc.ControllerActionInvoker.GetParameterValue(ControllerContext controllerContext, ParameterDescriptor parameterDescriptor) +317
   System.Web.Mvc.ControllerActionInvoker.GetParameterValues(ControllerContext controllerContext, ActionDescriptor actionDescriptor) +117
   System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__1e(AsyncCallback asyncCallback, Object asyncState) +446
   System.Web.Mvc.Async.WrappedAsyncResult`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +130
   System.Web.Mvc.Async.AsyncControllerActionInvoker.BeginInvokeAction(ControllerContext controllerContext, String actionName, AsyncCallback callback, Object state) +302
   System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__17(AsyncCallback asyncCallback, Object asyncState) +30
   System.Web.Mvc.Async.WrappedAsyncResult`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +130
   System.Web.Mvc.Controller.BeginExecuteCore(AsyncCallback callback, Object state) +382
   System.Web.Mvc.Async.WrappedAsyncResult`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +130
   System.Web.Mvc.Controller.BeginExecute(RequestContext requestContext, AsyncCallback callback, Object state) +317
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.BeginExecute(RequestContext requestContext, AsyncCallback callback, Object state) +15
   System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__2(AsyncCallback asyncCallback, Object asyncState) +71
   System.Web.Mvc.Async.WrappedAsyncResult`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +130
   System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +249
   System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +50
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +16
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +301
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET 
Version:4.0.30319.18045 

Original issue reported on code.google.com by travis.illig on 22 Jul 2013 at 4:14

GoogleCodeExporter commented 8 years ago

Original comment by travis.illig on 8 Aug 2013 at 2:52

GoogleCodeExporter commented 8 years ago
The trouble appears to be with the way Glimpse replaces the action invoker. The 
default mechanism to create the action invoker runs through the 
DependencyResolver, but with Glimpse in place it seems to be a proxy around the 
default version of the action invoker.

When Glimpse is enabled, the IActionInvoker in place at the point of 
Controller.BeginExecuteCore is a dynamic proxy 
Castle.Proxies.AsyncControllerActionInvokerProxy.

The base class for that proxy is 
System.Web.Mvc.Async.AsyncControllerActionInvoker and the __target on the proxy 
is correctly Autofac.Integration.Mvc.ExtensibleActionInvoker. There seem to 
also be two mixins:
* 
Glimpse.Core.Framework.CastleDynamicProxyWrapper<System.Web.Mvc.Async.AsyncContr
ollerActionInvoker>
* Glimpse.Mvc.AlternateType.ActionInvokerStateMixin

What appears to be happening is the target of the dynamic proxy is getting 
bypassed in favor of calling the base 
AsyncControllerActionInvoker.GetParameterValue instead of the overridden one in 
the Autofac invoker.

Guessing this is something to do with the way the dynamic proxies in Glimpse 
get set up. I think I'm going to have to file something with Glimpse on this 
one; it doesn't appear to be something we can fix from our end.

Original comment by travis.illig on 8 Aug 2013 at 3:26

GoogleCodeExporter commented 8 years ago
It appears this has been an issue for a few months with Glimpse. Others have 
reported it - issue 328 for them: https://github.com/Glimpse/Glimpse/issues/328

Original comment by travis.illig on 8 Aug 2013 at 3:30

GoogleCodeExporter commented 8 years ago
Unfortunately, it looks like it may be a while until Glimpse can get a fix for 
this. See here for details:
https://github.com/Glimpse/Glimpse/issues/328#issuecomment-22346241

The workaround right now is to turn off the Glimpse ActionInvoker 
functionality, which is outlined in that comment on the GitHub issue.

In the meantime, I'll keep this open and keep watching for a resolution, but 
again, there's nothing we can do from this end.

Original comment by travis.illig on 8 Aug 2013 at 8:59

GoogleCodeExporter commented 8 years ago
This continues to be a problem with Glimpse 1.8.0 and Glimpse.Mvc5 1.5.1.

Original comment by travis.illig on 14 Nov 2013 at 5:49

GoogleCodeExporter commented 8 years ago
Moved issue to GitHub: https://github.com/autofac/Autofac/issues/451

Subsequent issue management will be held there; closing the issue on Google 
Code as "WontFix" because we will handle issue resolution on GitHub.

Original comment by travis.illig on 11 Feb 2014 at 12:04