1

Closed

Private action methods are also autogenerated causing compilation failures

description

If there are private actions then T4MVC generates a public method stub in its autogenerated partial class for the controller. This causes a compilation failure cos now there are two methods with the same definition.

I know private actions cannot be used directly but there are use cases for them. One is encouraged to use the ChildActionOnly attribute on private methods but it need not necessarily be followed by everyone.

Controller code to reproduce the issue.

private ActionResult MyAction()
    {
       return AnotherAction();
    }
generated stub:

[NonAction]
    [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
    public System.Web.Mvc.ActionResult MyAction() {
        return new T4MVC_ActionResult(Area, Name, ActionNames.MyAction);
    }
Closed Feb 14, 2013 at 12:00 AM by davidebbo

comments

davidebbo wrote Oct 5, 2012 at 7:51 PM

So to make sure I understand, your expectation is that T4MVC should not generate anything at all for such private actions, right?

davidebbo wrote Oct 5, 2012 at 8:21 PM

Hmmm, I'm confused because T4MVC already ignores private methods. See T4MVC.tt around line 968:
        // Ignore non-public methods
        if (method.Access != vsCMAccess.vsCMAccessPublic)
            continue;
And when I tried it, it indeed didn't generate and code for it. Not sure what's different in your case.

davidebbo wrote Feb 14, 2013 at 12:00 AM

Closing as I could not repro this and didn't get more info on reproing.