nancy

Nancy.Json.JsonSettings in Nancy v2


I'm upgrading my project from Nancy 1.4.5 -> 2.0

And I have errors:

public class AppBootstrapper : AutofacNancyBootstrapper
{
    private readonly ILifetimeScope _scope;

    public AppBootstrapper(ILifetimeScope scope)
    {
        _scope = scope;
    }

    protected override ILifetimeScope GetApplicationContainer()
    {
        return _scope;
    }

    protected override void ApplicationStartup(ILifetimeScope container, IPipelines pipelines)
    {
        JsonSettings.MaxJsonLength = int.MaxValue;
        JsonSettings.RetainCasing = true;

        base.ApplicationStartup(container, pipelines);
    }
}

}

Error CS0103 The name 'JsonSettings' does not exist in the current context

How can I resolve this issue?


Solution

  • I added method to AppBootstrapper class:

    public class AppBootstrapper : DefaultNancyBootstrapper
    {
        public override void Configure(INancyEnvironment environment)
        {
            environment.Json(retainCasing: true);
        }
        ... other methods
    }
    

    And added maxJsonLength to web.config:

    <system.web.extensions>
      <scripting>
        <webServices>
          <jsonSerialization maxJsonLength="2147483647"/>
        </webServices>
      </scripting>
    </system.web.extensions>