namespaces not working

Feb 27, 2011 at 7:21 PM

I have a static JsonHelper class in Numina.SiteBuilder.Logic namespace. In my template I call

 

dynamic data = JsonHelper.NewObject();

 

which throws an error. This is whats in the list of errors...

 

ErrorText = "The name 'JsonHelper' does not exist in the current context"

 

in my config I have this... I cut out some stuff for simplicity

 

  <configSections>
    <section name="razorEngine" type="RazorEngine.Configuration.RazorEngineConfigurationSection, RazorEngine" requirePermission="false" />
  </configSections>
  <razorEngine>
    <namespaces>
      <add namespace="Numina.SiteBuilder.Logic" />
    </namespaces>
  </razorEngine>

Is this not right?

Feb 27, 2011 at 7:25 PM

If I use the full path it works...

Numina.SiteBuilder.Logic.JsonHelper.NewObject();
Coordinator
Mar 1, 2011 at 5:31 PM

I suspect it should be the following:

dynamic data = Logic.JsonHelper.NewObject();
  <configSections>
<section name="razorEngine" type="RazorEngine.Configuration.RazorEngineConfigurationSection, RazorEngine" requirePermission="false" />
</configSections>
<razorEngine>
<namespaces>
<add namespace="Numina.SiteBuilder" />
</namespaces>
</razorEngine>

But I can't tell without seeing the objects.

 

Mar 1, 2011 at 6:44 PM

This is what the class looks like

namespace Numina.SiteBuilder.Logic
{
    usings...

    public static class JsonHelper
    {
        public static string FixQuotes(string s) { ... }

        public static dynamic NewObject() { ... }

        public static dynamic NewArray(int size) { ... }

        public static string ToJson(dynamic d) { ... }

    }
}

Coordinator
Mar 1, 2011 at 6:55 PM

It looks like the Namespaces are only added on custom TemplateBase implementations. I'm not sure if Antaris did this on purpose or not - Hopefully he'll see this thread and chime in. :)

Coordinator
Mar 2, 2011 at 7:47 AM

lolwhoops, this is indeed a mistake. I've checked in a change, that won't be released until RazorEngine v2.2 is ready for release (which I haven't started yet). You could either download that changeset (7636), or you could make this temporary change to your configuration:

<razorEngine>
  <namespaces>
    <add namespace="Numina.SiteBuilder" />
  </namespaces>
  <templateServices default="Default">
    <add name="Default" language="CSharp" />
  </templateServices>
</razorEngine>

Mar 2, 2011 at 8:30 PM

updating the web.config worked. I will get latest and test that as well. thanks for taking a look at it.