Nancy- 0.17,startIndex不能大于String

时间:2013-04-28 08:44:50

标签: razor nancy

我升级到 NancyFx v0.17 。 当我点击其中包含模型的视图时,我现在收到以下错误。

[ArgumentOutOfRangeException: startIndex cannot be larger than length of string.
Parameter name: startIndex]
   System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy) +10695231
   System.String.Substring(Int32 startIndex) +12
   Nancy.Conventions.<>c__DisplayClass19.<BuildContentDelegate>b__e(ResponseFactoryCacheKey pathAndRootPair) +271
   System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory) +72
   Nancy.Conventions.<>c__DisplayClass2.<AddDirectory>b__0(NancyContext ctx, String root) +614
   Nancy.DefaultStaticContentProvider.GetContent(NancyContext context) +127
   Nancy.NancyEngine.HandleRequest(Request request, Func`2 preRequest) +198
   Nancy.NancyEngine.HandleRequest(Request request) +154
   Nancy.Hosting.Aspnet.NancyHandler.ProcessRequest(HttpContextBase context) +86
   Nancy.Hosting.Aspnet.NancyHttpRequestHandler.ProcessRequest(HttpContext context) +121
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +341
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69

升级后我没有改变任何内容,因此我的代码不应该是问题(因为它在 v0.16 之前5分钟工作)。

e.g。导致此错误的视图

http://localhost:9742/_Nancy/info (Diagnostics is turned on)

http://localhost:9742/messages/all

e.g。 NancyModule

public class MessageModule : BaseModule
    {
        public MessageModule() : base("messages")
        {
            var message = new Message
                        {
                            Id = 1 , 
                            Name = "ashutosh", 
                            Email= "ashutoshraina1989@gmail.com",
                            MessageContent ="Wassup Baker"
                        };
            var message2 = new Message
            {
                Id = 1,
                Name = "Awesome",
                Email = "awesomeness@gmail.com",
                MessageContent = "Wassup Baker"
            };
            var messages = new List<Message> {message, message2};
            Model = messages;

            Get["/all"] = parameters =>
                {
                    return View["/Message/Index", Model];
                };         
        }

对应视图

@inherits  NancyRazorViewBase<System.Collections.Generic.IEnumerable<Message>>

@{
    ViewBag.Title = "title";
    Layout = "/Common/_Layout";
}

@RenderBody()

<body>
    <section id ="Messages">
        <div>
            <div>
                <table>
                    <thead>
                        <tr>
                            <th>Name</th>
                            <th>Message</th>                               
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var m in Model)
                        {
                            <tr>
                                <td>@m.Name</td>
                                <td><p>@m.MessageContent</p></td>                            
                            </tr>
                        }
                    </tbody>
                </table>
            </div>
        </div>            
    </section>       
</body>

1 个答案:

答案 0 :(得分:2)

这已经解决了。您应该能够更新到0.17.1并且错误应该消失。谢谢