I'm using Castle Windsor to do various AOP stuff in my web application. I'm having an issue with a controller action method with an optional parameter with a default value:
public virtual ActionResult MyActionMethod(int? dummy=null) {}
public virtual ActionResult MyActionMethod(int? dummy=3) {}
Assume that the action is invoked without any matching parameters (e.g. http://host/MyController/MyActionmethod)
The issue is that when the controller action invoker tries to figure out what action to invoke on the controller it blows up at the call to ActionDescriptor.ExtractParameterFromDictionary because instead of a null or 3 value in the arguments it's parsing the argument is of type System.Reflection.Missing.
At this point the extractor should look to verify that the action is optional and has a default value and use that value rather than throw up. I don't think this behavior is incorrect -- Castle passing in System.Reflection.Missing -- and I don't think this is a bug with Castle because it's doing the semantically correct thing (the argument is actually missing).
Comments: To the op (timiscool999): A possible workaround to the problem at hand: Since the actual action method is not being intercepted by Windsor (even if it is virtual), but instead it intercepts the EndExecute method of the base Controller class. Therefore if you simply remove the 'virtual' modifier from the method, the exception would not occur. Please let us know if this unblocks you for now.
public virtual ActionResult MyActionMethod(int? dummy=null) {}
public virtual ActionResult MyActionMethod(int? dummy=3) {}
Assume that the action is invoked without any matching parameters (e.g. http://host/MyController/MyActionmethod)
The issue is that when the controller action invoker tries to figure out what action to invoke on the controller it blows up at the call to ActionDescriptor.ExtractParameterFromDictionary because instead of a null or 3 value in the arguments it's parsing the argument is of type System.Reflection.Missing.
At this point the extractor should look to verify that the action is optional and has a default value and use that value rather than throw up. I don't think this behavior is incorrect -- Castle passing in System.Reflection.Missing -- and I don't think this is a bug with Castle because it's doing the semantically correct thing (the argument is actually missing).
Comments: To the op (timiscool999): A possible workaround to the problem at hand: Since the actual action method is not being intercepted by Windsor (even if it is virtual), but instead it intercepts the EndExecute method of the base Controller class. Therefore if you simply remove the 'virtual' modifier from the method, the exception would not occur. Please let us know if this unblocks you for now.