简体   繁体   English

AccessViolationException未处理

[英]AccessViolationException was unhandled

I'm attempting to use Steve Sanderson's blog post in order to edit a variable length list in my ASP MVC 3 view. 我正在尝试使用Steve Sanderson的博客文章来编辑我的ASP MVC 3视图中的可变长度列表。 The project builds fine, however whenever the partial view is rendered the program blows up on the using(Html.BeginColletionItem() line with this error: 该项目构建正常,但无论何时呈现局部视图,程序都会在using(Html.BeginColletionItem()行时出现此错误:

AccessViolationException was unhandled
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Here's a screen shot of the full exception 这是完整例外的屏幕截图

在此输入图像描述

Complete stack trace below 完整的堆栈跟踪如下

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, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

Partial View 局部视图

@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, "NullableDate", new { @class = "relDistCode1", maxlength = 3 })</td>
        @Html.HiddenFor(model => model.ID)
        @Html.HiddenFor(model => model.RelCodeOrdinal)
    </tr>
}

View 视图

    <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>

Controller 调节器

    [HandleProcessCorruptedStateExceptions]
    public ViewResult NewRelationshipCode()
    {
        return View("AddRelationshipCodePartial", new AgentRelationshipCodes());
    }

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; }
    }
}

EDIT 编辑

I've been able to get the demo working in a project outside the solution I'm using right now, so it apparently has to do with some dlls in this workspace. 我已经能够在我正在使用的解决方案之外的项目中使用该演示,因此它显然与此工作空间中的某些dll有关。 Now I'm above my paygrade, however, as I'm unsure how to debug something like this. 然而,现在我高于我的薪水,因为我不确定如何调试这样的东西。 Here are the exceptions that are identified by WinDbg prior to Visual Studio throwing the AccessViolationException . 以下是在Visual Studio抛出AccessViolationException之前由WinDbg标识的异常。 There is A LOT of information in between the exceptions being thrown, if that is needed by anyone please let me know. 抛出异常之间有很多信息,如果有人需要,请告诉我。

*** WARNING: Unable to verify checksum for C:\Windows\assembly\NativeImages_v4.0.30319_32\mscorlib\d12f4fda3d1bfabf888342e96983e9a7\mscorlib.ni.dll
*** ERROR: Module load completed but symbols could not be loaded for C:\Windows\assembly\NativeImages_v4.0.30319_32\mscorlib\d12f4fda3d1bfabf888342e96983e9a7\mscorlib.ni.dll

*** WARNING: Unable to verify checksum for C:\Windows\assembly\NativeImages_v4.0.30319_32\System.Xaml\9d3572e8c3c314a0f12383d41e8bee78\System.Xaml.ni.dll
*** ERROR: Module load completed but symbols could not be loaded for C:\Windows\assembly\NativeImages_v4.0.30319_32\System.Xaml\9d3572e8c3c314a0f12383d41e8bee78\System.Xaml.ni.dll

*** WARNING: Unable to verify checksum for C:\Windows\assembly\NativeImages_v4.0.30319_32\Presentatio5ae0f00f#\8711b01d60a94d6ef6a02d7fd0578493\PresentationFramework.ni.dll
*** ERROR: Module load completed but symbols could not be loaded for C:\Windows\assembly\NativeImages_v4.0.30319_32\Presentatio5ae0f00f#\8711b01d60a94d6ef6a02d7fd0578493\PresentationFramework.ni.dll

*** WARNING: Unable to verify checksum for C:\Windows\assembly\NativeImages_v4.0.30319_32\WindowsBase\ac2e26bafa70e93b307087d7fe6b9dd2\WindowsBase.ni.dll
*** ERROR: Module load completed but symbols could not be loaded for C:\Windows\assembly\NativeImages_v4.0.30319_32\WindowsBase\ac2e26bafa70e93b307087d7fe6b9dd2\WindowsBase.ni.dll

*** WARNING: Unable to verify checksum for C:\Windows\assembly\NativeImages_v4.0.30319_32\Microsoft.V4e91a071#\207156ac71b58fb31310a2f78c3d0c44\Microsoft.VisualStudio.Web.Application.ni.dll
*** ERROR: Module load completed but symbols could not be loaded for C:\Windows\assembly\NativeImages_v4.0.30319_32\Microsoft.V4e91a071#\207156ac71b58fb31310a2f78c3d0c44\Microsoft.VisualStudio.Web.Application.ni.dll

UPDATE UPDATE

By selecting the "Native Code" option in the project's Debuggers menu 通过在项目的Debuggers菜单中选择“Native Code”选项

在此输入图像描述

I now receive a slightly more detailed error message: 我现在收到一个稍微更详细的错误消息:

在此输入图像描述

Lastly, by switching to IIS Express as suggested below I am still receiving the AccessViolationException . 最后,通过切换到IIS Express,如下所示,我仍然收到AccessViolationException Here are the settings I used to enable IIS for debugging (under project properties) 以下是我用于启用IIS进行调试的设置(在项目属性下)

在此输入图像描述

Here is the error message 这是错误消息

在此输入图像描述

Call stack: 调用堆栈:

在此输入图像描述

Seems to me that you're working harder than you need to. 在我看来,你的工作比你需要的更努力。

First, replace the foreach with a for loop, passing the indexed element into an editor template. 首先,用for循环替换foreach,将索引元素传递给编辑器模板。 This will establish your template context. 这将建立您的模板上下文。

<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>

Then create an editor template called AgentRelationshipCodes.cshtml (in Views/Shared/EditorTemplates) 然后创建一个名为AgentRelationshipCodes.cshtml的编辑器模板(在Views / Shared / EditorTemplates中)

@model Monet.Models.AgentRelationshipCodes
<tr>
    <td>@Html.EditorFor(model => model.EffectiveDate, "NullableDate", new { @class = "relCodeDate2" })</td>
    <td>@Html.EditorFor(model => model.RelationshipId, "NullableDate", new { @class = "relDistCode1", maxlength = 3 })</td>
    @Html.HiddenFor(model => model.ID)
    @Html.HiddenFor(model => model.RelCodeOrdinal)
</tr>

This eliminates the need for the custom helpers which are what appear to be causing the problem. 这消除了对看起来引起问题的自定义助手的需要。

Lastly, for adding new elements - move the fieldset to a partial: 最后,添加新元素 - 将字段集移动到部分:

<script>
    $(document).ready(function() {
       $(".addCode").click(function () {
            $('#fieldset').load('@Url.Action("NewRelationshipCode", "AgentTransmission")',$('#fieldset').closest('form').serialize());
       });
    });
</script>

<div id="fieldset">
   @Html.Partial("fieldset");
</div>

And return the fieldset view from your NewRelationshipCode action method: 并从NewRelationshipCode操作方法返回fieldset视图:

[HandleProcessCorruptedStateExceptions]
public ViewResult NewRelationshipCode(YourViewModel model)
{
    model.AgentRelationshipCodes.Add(new AgentRelationshipCodes());
    return View("fieldset", model);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C#上未处理AccessViolationException - AccessViolationException unhandled on C# 在EMGU CV中未处理AccessViolationException - AccessViolationException was unhandled in EMGU CV 未处理且无法捕获的System.AccessViolationException - Unhandled and Uncatchable System.AccessViolationException 发生类型为&#39;System.AccessViolationException&#39;的未处理异常 - An unhandled exception of type 'System.AccessViolationException' occurred 测量未使用其他字体AccessViolationException的字符串 - Measuring a string with a different font AccessViolationException was Unhandled C#托管代码中的“AccessViolationException未处理”错误 - “AccessViolationException was unhandled” error in C# Managed Code 未处理的异常:System.AccessViolationException:尝试读取或写入 - Unhandled Exception: System.AccessViolationException: Attempted to read or write USB AccessViolationException的C#.NET ReadFile未处理 - C# .NET ReadFile from USB AccessViolationException was unhandled OpenCLNet.dll中发生了类型为&#39;System.AccessViolationException&#39;的未处理异常 - An unhandled exception of type 'System.AccessViolationException' occurred in OpenCLNet.dll System.AccessViolationException未处理c#Windows Phone 8 - System.AccessViolationException was unhandled c# Windows Phone 8
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM