This project is read-only.

Problems when using T4MVC in non MVC library

Nov 17, 2012 at 5:43 PM
Edited Nov 17, 2012 at 5:43 PM


I am using T4MVC and I created a Sitemap on a different class library.

Basically the sitemap accepts profiles based on the following:

  public class SitemapProfileBase {

    private readonly IList<SitemapNode> _nodes;

    public IList<SitemapNode> Nodes { get { return _nodes; } }

    public SitemapProfileBase() {
      _nodes = new List<SitemapNode>();
    } // SitemapProfileBase

    public void Add(ActionResult location, SitemapFrequency? frequency = null, DateTime? modified = null, Double? priority = null) {
      _nodes.Add(new SitemapNode(location, frequency, modified, priority));
    } // Add

So then in my MVC application I create a profile:

  public class SitemapProfile : SitemapProfileBase {
    public SitemapProfile() {    
      Add(MVC.Home.Index().GetRouteValueDictionary(), SitemapFrequency.Daily, DateTime.UtcNow, 1.0);
    } // Build
  } // SitemapProfile

But when I add it to my Sitemap in global.asax I get an error:

The type initializer for 'MVC' threw an exception.

StructureMap Exception Code:  202\nNo Default Instance defined for PluginFamily MVCSite.ITranslator

The point is that there is not ITranslator being used in Sitemap ... Only in MVC.Home.Index action ...

Inside my Sitemap I am using T4MVC extensions to generate URL using UrlHelper.Action.

Any idea what might be wrong?

Thank You,


Nov 18, 2012 at 5:08 AM

First thing I would try is to replace the T4MVC calls with regular MVC calls to see if the issue is T4MVC related or something else. I don't have all the context, but based on the error, it seems fairly likely to be unrelated.


Nov 20, 2012 at 2:57 PM

Your Add function should accept a RouteValuesDictionary, not an ActionResult for the location parameter, thought the compiler should have caught this discrepancy. Do you have an Add method that takes an object, as this can cause strange errors like you are seeing.