MVC2 & 2010 Support

Mar 3, 2010 at 11:00 PM

Hello Again,

I've been working through getting this running under .Net 4 and I am pretty close. There have been few issues so far except for this one.

For some reason, during initial startup, the  MvcExControllerBuilder. CopyDefaultAttributeByPropertyMapping method is throwing an exception at this line:


\MvcEx\Controllers\MvcExControllerBuilder.cs, line 373

 // Perform the property copying

attributeBuilder = new CustomAttributeBuilder(


                                            new Object[] { },



System.ArgumentNullException was unhandled by user code

  Message=Value cannot be null.

Parameter name: con




       at System.Reflection.Emit.CustomAttributeBuilder.InitCustomAttributeBuilder(ConstructorInfo con, Object[] constructorArgs, PropertyInfo[] namedProperties, Object[] propertyValues, FieldInfo[] namedFields, Object[] fieldValues)

       at System.Reflection.Emit.CustomAttributeBuilder..ctor(ConstructorInfo con, Object[] constructorArgs, PropertyInfo[] namedProperties, Object[] propertyValues)

       at MvcEx.Controllers.MvcExControllerBuilder.CopyDefaultAttributeByPropertyMapping(Object attribute, Type attributeType) in C:\Users\rick.MATRIX6\Documents\Visual Studio 2010\Workspaces\GreatAmerican\Main\Source\MvcEx\Controllers\MvcExControllerBuilder.cs:line 373

       at MvcEx.Controllers.MvcExControllerBuilder.CopyActionMethodAttributes(MethodInfo methodInfo, MethodBuilder methodBuilder) in C:\Users\rick.MATRIX6\Documents\Visual Studio 2010\Workspaces\GreatAmerican\Main\Source\MvcEx\Controllers\MvcExControllerBuilder.cs:line 304

       at MvcEx.Controllers.MvcExControllerBuilder.CreateMethodOnDynamicController(TypeBuilder controllerType, MethodInfo methodInfo) in C:\Users\rick.MATRIX6\Documents\Visual Studio 2010\Workspaces\GreatAmerican\Main\Source\MvcEx\Controllers\MvcExControllerBuilder.cs:line 197

       at MvcEx.Controllers.MvcExControllerBuilder.CreateType(String controllerName, Type baseControllerType) in C:\Users\rick.MATRIX6\Documents\Visual Studio 2010\Workspaces\GreatAmerican\Main\Source\MvcEx\Controllers\MvcExControllerBuilder.cs:line 135

       at MvcEx.Controllers.MvcExControllerBuilder.GetControllerType(String controllerName, Type baseControllerType) in C:\Users\rick.MATRIX6\Documents\Visual Studio 2010\Workspaces\GreatAmerican\Main\Source\MvcEx\Controllers\MvcExControllerBuilder.cs:line 95

       at MvcEx.Controllers.MvcExControllerFactory.CreateController(RequestContext requestContext, String controllerName) in C:\Users\rick.MATRIX6\Documents\Visual Studio 2010\Workspaces\GreatAmerican\Main\Source\MvcEx\Controllers\MvcExControllerFactory.cs:line 94

       at System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext)

       at System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext)

       at System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext)

       at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()

       at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)



It looks like the ConstructorInfo object is null.

I tried stepping through the 2008 version of your code and noticed that the methods and parameters that are being copied are very different.

Any help would be appreciated.



Mar 3, 2010 at 11:39 PM

FYI - switching back to 3.5 does fix the issue.


Mar 4, 2010 at 9:00 AM


I'll need to set up a machine with 2010 soon and start to look at different environments - if you want to dig a bit deeper into this I'll explain what is going on:

Because controller actions have attributes on them, and we're generating a new controller comprised of all of those actions, the attributes need copying across somehow.

By default, MvcEx will find an empty constructor and then copy across all the properties (this works for a lot of attributes).

Where specified, MvcEx will use a different method  to manually construct the attribute

The lines of code above would suggest that it's falling back to the default behaviour - which means it's not recognising the attributes as something special (could be to do with versions you are linking)

What needs to be done (feel free to submit a patch), is part of the configuration for the controller builder should be telling it about the attributes that need special handling, and injecting the behaviour for that - then we can write a configuration for .NET4 and its new attributes.


This of course brings us back to the question of why bother trying to build controllers out of actions from different sources - MS MVC isn't built like that, and to force it to do that in order to give us something really flexible is probably heinous mis-use (I see now why the FubuMVC guys ended up just writing their own MVC framework)

Mar 4, 2010 at 12:59 PM

I think for now I'll stick with 3.5 until 4.0 is released. Do you think MEF would be a better way of accomplishing this without some of the complexity?

Thank you for your time.


Mar 4, 2010 at 1:45 PM

I have started an MEF version - some of the trickiness still lies in making sure those attributes come across. Tis the subject of my next blog entry hopefully :)

I am contemplating going back to simply selecting a controller from the relevant place, but it does seem like either way you've got a kludge to work around MS MVC.

Aug 17, 2010 at 10:25 PM

I was wondering if there has been any movement on supporting MVC2 and VS 2010?

I have a fairly good sized project starting up and was hoping to use this as a starting point.