Wilson UIMapper and CodeSmith Tip

Date Published: 23 March 2005

Wilson UIMapper and CodeSmith Tip

I’m sure this is documented as being a requirement, but if you miss that part and just get the error, you’ll have a hard time associating the error with the requirement that corrects things. In my case, I was trying to use the Wilson UIMapper package to build the UI config files for some assemblies I had built using Paul Welter’s LoreSoft WilsonORMapper CodeSmith Templates. Everything was going fine, I created the OR mapping file, then the OR classes, built them with a NAnt script. But then when I got to the last step, generating the UIMapping files, I kept getting a System.Reflection.TypeLoadException, like this one:

System.Reflection.ReflectionTypeLoadException: One or more of the types in the assembly unable to load.\
at System.Reflection.Module.GetTypesInternal(StackCrawlMark& stackMark)\
at System.Reflection.Assembly.GetTypes()\
at _CodeSmithTemplate.WilsonUIHelper_cst.RootMappings() in c:Documents and SettingsSteveLocal SettingsTempyrdsrjwu.0.cs:line 71\
— End of inner exception stack trace —\
at _CodeSmithTemplate.WilsonUIHelper_cst.RootMappings() in c:Documents and SettingsSteveLocal SettingsTempyrdsrjwu.0.cs:line 92\
at _CodeSmithTemplate.WilsonUIHelper_cst.Generate() in c:Documents and SettingsSteveLocal SettingsTempyrdsrjwu.0.cs:line 54\
at _CodeSmithTemplate.WilsonUIHelper_cst.__RenderMethod1(TextWriter writer, Control control) in c:Documents and SettingsSteveLocal SettingsTempyrdsrjwu.0.cs:line 338\
at CodeSmith.Engine.DelegateControl.Render(TextWriter writer)\
at CodeSmith.Engine.Control.RenderChildren(TextWriter writer)\
at CodeSmith.Engine.CodeTemplate.Render(TextWriter writer)\
at CodeSmith.Engine.CodeTemplate.RenderToString()\
at CodeSmith.Gui.CodeTemplateGenerator.b(Object , EventArgs )

So, what’s the fix? Well, as Paul Wilson so graciously informed me this morning, you have to have any referenced assemblies used by the Entities classes (the ones generated by the ORMapper templates) in the same folder as the WilsonUIHelper.cst CodeSmith Template. It also needs to have its own AssemblyHelper.dll assembly with it (which is how it ships). So I copied the .cst file to my references folder in my Nant project where I had copies of all the Wilson assemblies (WilsonORMapper.dll, in particular), and re-ran the template. Voila! Works like a charm.

Steve Smith

About Ardalis

Software Architect

Steve is an experienced software architect and trainer, focusing on code quality and Domain-Driven Design with .NET.