我升级到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 分钟)。
例如导致此错误的视图
http://localhost:9742/_Nancy/info (Diagnostics is turned on)
http://localhost:9742/messages/all
例如南希模块
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>