Can't seem to override CreateController in the DefaultControllerFactory
I'm trying to implement Elmah into my MVC application using this great tutorial.
http://dotnetdarren.wordpress.com/20开发者_C百科10/07/27/logging-on-mvc-part-1/
Everything seems fine, but when I build, I get
no suitable method found to override
Below is the class I took right from the sample
public class ErrorHandlingControllerFactory : DefaultControllerFactory
{
/// <summary>
/// Injects a custom attribute
/// on every action that is invoked by the controller
/// </summary>
/// <param name="requestContext">The request context</param>
/// <param name="controllerName">The name of the controller</param>
/// <returns>An instance of a controller</returns>
public override IController CreateController(
RequestContext requestContext,
string controllerName)
{
var controller =
base.CreateController(requestContext,
controllerName);
var c = controller as Controller;
if (c != null)
{
c.ActionInvoker =
new ErrorHandlingActionInvoker(
new HandleErrorWithELMAHAttribute());
}
return controller;
}
}
Well, after much more research, I found the issue from this link
http://forums.asp.net/t/1622810.aspx
Needed to add a reference to System.Web.Routing since it was in a seperate project.
I was able to build successfully:
- Created a new Empty ASP.NET MVC 2 project
- From the tutorial, copied in the code for the
HandleErrorWithELMAHAttribute
class. - Copied the code for the
ErrorHandlingActionInvoker
class. - Copied the code for the
ErrorHandlingControllerFactory
class. - Added necessary
using
statements and a reference to ELMAH.
Then, to check, I replaced the original code for the ErrorHandlingControllerFactory
with the code from your question, and it also compiled without error.
I was able to get that error was by adding a class named DefaultControllerFactory
so that ErrorHandlingControllerFactory
would be inheriting from that. It seems unlikely, but you may want to make sure you are inheriting from the correct class.
精彩评论