c# – AccessViolationException未处理
我正在尝试使用
Steve Sanderson’s blog post来编辑我的ASP MVC 3视图中的可变长度列表.该项目构建良好,但是无论何时渲染部分视图,该程序会在使用(Html.BeginColletionItem()行中冒出此错误:
AccessViolationException was unhandled Attempted to read or write protected memory. This is often an indication that other memory is corrupt. 这是一个完整例外的屏幕截图 完成堆栈跟踪下面 at Microsoft.VisualStudio.WebHost.Host.ProcessRequest(Connection conn) at Microsoft.VisualStudio.WebHost.Server.OnSocketAccept(Object acceptedSocket) at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext,ContextCallback callback,Object state,Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext,Boolean preserveSyncCtx) at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() at System.Threading.ThreadPoolWorkQueue.Dispatch() at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback() 部分视图 @model Monet.Models.AgentRelationshipCodes @using (Html.BeginCollectionItem("AgentRelationshipCodes")) @*Exception thrown here*@ { <tr> <td>@Html.EditorFor(model => model.EffectiveDate,"NullableDate",new { @class = "relCodeDate2" })</td> <td>@Html.EditorFor(model => model.RelationshipId,new { @class = "relDistCode1",maxlength = 3 })</td> @Html.HiddenFor(model => model.ID) @Html.HiddenFor(model => model.RelCodeOrdinal) </tr> } 视图 <script> $(document).ready(function() { $(".addCode").click(function () { $.ajax({ url: '@Url.Action("NewRelationshipCode","AgentTransmission")',dataType: 'html',cache: false,success: function (html) { console.log(html); $("#Experiment > tbody").append(html); } }) }); }); </script> . . <fieldset> <legend>Relationship Codes</legend> <table id="Experiment"> <thead> <tr> <th>Relationship Effective Date</th> <th>Relationship Dist Code</th> </tr> </thead> <tbody> @foreach (var item in Model.AgentRelationshipCodes) { @Html.Partial("AddRelationshipCodePartial",item) } </tbody> </table> <br/> <a href="javascript:void(0)" class ="addCode">Add Another</a> </fieldset> 调节器 [HandleProcessCorruptedStateExceptions] public ViewResult NewRelationshipCode() { return View("AddRelationshipCodePartial",new AgentRelationshipCodes()); } AgentRelationshipCodes namespace Monet.Models { using System; using System.Collections.Generic; public partial class AgentRelationshipCodes { public int ID { get; set; } public int RelCodeOrdinal { get; set; } public string RelationshipId { get; set; } public Nullable<System.DateTime> EffectiveDate { get; set; } public System.DateTime LastChangeDate { get; set; } public string LastChangeId { get; set; } public virtual AgentTransmission AgentTransmission { get; set; } } } 编辑 我已经能够在现在使用的解决方案之外的项目中工作,所以它显然与这个工作区中的一些dll有关.现在我在我的工资级别以上,因为我不确定如何调试这样的东西.以下是Visual Studio抛出AccessViolationException之前由WinDbg标识的异常.在抛出异常之间有很多信息,如果任何人需要,请让我知道. *** WARNING: Unable to verify checksum for C:WindowsassemblyNativeImages_v4.0.30319_32mscorlibd12f4fda3d1bfabf888342e96983e9a7mscorlib.ni.dll *** ERROR: Module load completed but symbols could not be loaded for C:WindowsassemblyNativeImages_v4.0.30319_32mscorlibd12f4fda3d1bfabf888342e96983e9a7mscorlib.ni.dll *** WARNING: Unable to verify checksum for C:WindowsassemblyNativeImages_v4.0.30319_32System.Xaml9d3572e8c3c314a0f12383d41e8bee78System.Xaml.ni.dll *** ERROR: Module load completed but symbols could not be loaded for C:WindowsassemblyNativeImages_v4.0.30319_32System.Xaml9d3572e8c3c314a0f12383d41e8bee78System.Xaml.ni.dll *** WARNING: Unable to verify checksum for C:WindowsassemblyNativeImages_v4.0.30319_32Presentatio5ae0f00f#8711b01d60a94d6ef6a02d7fd0578493PresentationFramework.ni.dll *** ERROR: Module load completed but symbols could not be loaded for C:WindowsassemblyNativeImages_v4.0.30319_32Presentatio5ae0f00f#8711b01d60a94d6ef6a02d7fd0578493PresentationFramework.ni.dll *** WARNING: Unable to verify checksum for C:WindowsassemblyNativeImages_v4.0.30319_32WindowsBaseac2e26bafa70e93b307087d7fe6b9dd2WindowsBase.ni.dll *** ERROR: Module load completed but symbols could not be loaded for C:WindowsassemblyNativeImages_v4.0.30319_32WindowsBaseac2e26bafa70e93b307087d7fe6b9dd2WindowsBase.ni.dll *** WARNING: Unable to verify checksum for C:WindowsassemblyNativeImages_v4.0.30319_32Microsoft.V4e91a071#207156ac71b58fb31310a2f78c3d0c44Microsoft.VisualStudio.Web.Application.ni.dll *** ERROR: Module load completed but symbols could not be loaded for C:WindowsassemblyNativeImages_v4.0.30319_32Microsoft.V4e91a071#207156ac71b58fb31310a2f78c3d0c44Microsoft.VisualStudio.Web.Application.ni.dll UPDATE 通过在项目的“调试器”菜单中选择“本地代码”选项 我现在收到一个稍微更详细的错误信息: 最后,通过如下所示切换到IIS Express,我仍然收到AccessViolationException.以下是我用于启用IIS进行调试的设置(在项目属性下) 这是错误消息 调用堆栈: 解决方法
似乎我比你需要更努力工作.
首先,使用for循环替换foreach,将索引的元素传递给编辑器模板.这将建立您的模板上下文. <fieldset> <legend>Relationship Codes</legend> <table id="Experiment"> <thead> <tr> <th>Relationship Effective Date</th> <th>Relationship Dist Code</th> </tr> </thead> <tbody> @for (var i = 0; i < Model.AgentRelationshipCodes.Count(); i++) { @Html.EditorFor(model => model.AgentRelationshipCodes[i]) } </tbody> </table> <br/> <a href="javascript:void(0)" class ="addCode">Add Another</a> </fieldset> 然后创建一个名为AgentRelationshipCodes.cshtml的编辑器模板(在Views / Shared / EditorTemplates中) @model Monet.Models.AgentRelationshipCodes <tr> <td>@Html.EditorFor(model => model.EffectiveDate,new { @class = "relCodeDate2" })</td> <td>@Html.EditorFor(model => model.RelationshipId,maxlength = 3 })</td> @Html.HiddenFor(model => model.ID) @Html.HiddenFor(model => model.RelCodeOrdinal) </tr> 这样就不再需要自定义的帮助者,而这些帮助者似乎是导致问题的原因. 最后,添加新元素 – 将字段集移动到部分: <script> $(document).ready(function() { $(".addCode").click(function () { $('#fieldset').load('@Url.Action("NewRelationshipCode",$('#fieldset').closest('form').serialize()); }); }); </script> <div id="fieldset"> @Html.Partial("fieldset"); </div> 并从NewRelationshipCode操作方法返回fieldSet视图: [HandleProcessCorruptedStateExceptions] public ViewResult NewRelationshipCode(YourViewModel model) { model.AgentRelationshipCodes.Add(new AgentRelationshipCodes()); return View("fieldset",model); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |