3

Closed

Multiple inherited basecontrollers get exception

description

Here's how my project is set up:

(dll project)
\SpecialControllers\MyBaseController.cs

(web project)
\Controllers\BaseController.cs (inherits from MyBaseController in dll)
\Controllers\BlahController.cs (inherits from BaseController)

When I try and run the T4MVC.TT, I get a "The parameter is incorrect" exception:

Error 453 Running transformation: System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
at EnvDTE.CodeModel.CodeTypeFromFullName(String Name)
at Microsoft.VisualStudio.TextTemplatingBEEA4E0944F0D14FC54DC446F9BC774ADE781DE91C66FCD39F1DD090997E0F911280F77D1D6E5330FB282378C53619EA41FD87B2733A52EF1C3F663BAC1A1E67.GeneratedTextTransformation.ProcessControllerActionMethods(ControllerInfo controllerInfo, CodeClass2 current) in (redacted)\T4MVC.tt:line 950
at Microsoft.VisualStudio.TextTemplatingBEEA4E0944F0D14FC54DC446F9BC774ADE781DE91C66FCD39F1DD090997E0F911280F77D1D6E5330FB282378C53619EA41FD87B2733A52EF1C3F663BAC1A1E67.GeneratedTextTransformation.ProcessControllerType(CodeClass2 type, AreaInfo area, DateTime controllerLastWriteTime) in (redacted)\T4MVC.tt:line 915
at Microsoft.VisualStudio.TextTemplatingBEEA4E0944F0D14FC54DC446F9BC774ADE781DE91C66FCD39F1DD090997E0F911280F77D1D6E5330FB282378C53619EA41FD87B2733A52EF1C3F663BAC1A1E67.GeneratedTextTransformation.ProcessControllersRecursive(ProjectItem projectItem, AreaInfo area) in (redacted)\T4MVC.tt:line 863
at Microsoft.VisualStudio.TextTemplatingBEEA4E0944F0D14FC54DC446F9BC774ADE781DE91C66FCD39F1DD090997E0F911280F77D1D6E5330FB282378C53619EA41FD87B2733A52EF1C3F663BAC1A1E67.GeneratedTextTransformation.ProcessControllersRecursive(ProjectItem projectItem, AreaInfo area) in (redacted)\T4MVC.tt:line 852
at Microsoft.VisualStudio.TextTemplatingBEEA4E0944F0D14FC54DC446F9BC774ADE781DE91C66FCD39F1DD090997E0F911280F77D1D6E5330FB282378C53619EA41FD87B2733A52EF1C3F663BAC1A1E67.GeneratedTextTransformation.ProcessAreaControllers(ProjectItems areaFolderItems, AreaInfo area) in (redacted)\T4MVC.tt:line 836
at Microsoft.VisualStudio.TextTemplatingBEEA4E0944F0D14FC54DC446F9BC774ADE781DE91C66FCD39F1DD090997E0F911280F77D1D6E5330FB282378C53619EA41FD87B2733A52EF1C3F663BAC1A1E67.GeneratedTextTransformation.ProcessArea(ProjectItems areaFolderItems, String name) in (redacted)\T4MVC.tt:line 822
at Microsoft.VisualStudio.TextTemplatingBEEA4E0944F0D14FC54DC446F9BC774ADE781DE91C66FCD39F1DD090997E0F911280F77D1D6E5330FB282378C53619EA41FD87B2733A52EF1C3F663BAC1A1E67.GeneratedTextTransformation.ProcessAreas(Project project) in (redacted)\T4MVC.tt:line 794
at Microsoft.VisualStudio.TextTemplatingBEEA4E0944F0D14FC54DC446F9BC774ADE781DE91C66FCD39F1DD090997E0F911280F77D1D6E5330FB282378C53619EA41FD87B2733A52EF1C3F663BAC1A1E67.GeneratedTextTransformation.PrepareDataToRender(TextTransformation tt) in (redacted)\T4MVC.tt:line 770
at Microsoft.VisualStudio.TextTemplatingBEEA4E0944F0D14FC54DC446F9BC774ADE781DE91C66FCD39F1DD090997E0F911280F77D1D6E5330FB282378C53619EA41FD87B2733A52EF1C3F663BAC1A1E67.GeneratedTextTransformation.TransformText() in (redacted)\T4MVC.tt:line 37 (redacted)\T4MVC.tt 950 1



If I change my BaseController.cs to inherit from the standard "Controller", T4MVC works just fine.
Closed Dec 28, 2012 at 5:46 AM by davidebbo
Ok, I got your workaround in. It's not ideal, but we're dealing with a weird VB bug here. Try 3.2.1 from nuget. Thanks!

comments

nicholashead8485 wrote Dec 7, 2012 at 6:28 PM

Is there some way I can try and diagnose this myself?

davidebbo wrote Dec 16, 2012 at 5:32 AM

If you share a minimal project that has this issue (e.g. via github), I can try to investigate. Or you can try to debug the .tt template as it executes to figure out what's going on. e.g. what's being passed to CodeTypeFromFullName that's making it unhappy?

nicholashead8485 wrote Dec 28, 2012 at 12:27 AM

davidebbo, I was able to fix this by wrapping the CodeTypeFromFullName code in a try/catch:

try {
                var codeType = prj.CodeModel.CodeTypeFromFullName(type.FullName);
                if (codeType != null && codeType.InfoLocation == vsCMInfoLocation.vsCMInfoLocationProject) {
                    type = (CodeClass2)codeType;
                    break;
                }
            } catch (System.ArgumentException) {
                continue;
            }
I don't know why CodeTypeFromFullName throws an ArgumentException in some cases (reading the docs it looks to me like it should return null if it can't match..)

But anyway, patching this in seems to have fixed the problem for me. I'd make a pull request, but I'm not 100% sure how to right now (I'm used to Github).

davidebbo wrote Dec 28, 2012 at 3:15 AM

Pull requests should be pretty straightforward if you know github. See http://codeplex.codeplex.com/wikipage?title=Forks.

I don't mind getting the change in, but what I do want to see is a repro case so I can understand what triggers this exception in the first place (since I don't think anyone else has seen it).

nicholashead8485 wrote Dec 28, 2012 at 4:19 AM

David,

Thanks. Here's the repro:

https://github.com/nicholashead/T4MVCIssue

davidebbo wrote Dec 28, 2012 at 5:09 AM

Thanks Nicholas, I'm able to repro the issue now. I'll try to make sense of what's different about the scenario.

davidebbo wrote Dec 28, 2012 at 5:26 AM

Ok, I think I see what's going on. Looks like a bug in the VB DTE project implementation, which throws instead of returning null when it's passed a type it doesn't know.