本文介绍了AccessViolationException了未处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用Steve桑德森的博客文章才能在我的ASP MVC 3视图编辑一个可变长度的名单。该项目建立正常,但是每当局部视图渲染程序与此错误使用(Html.BeginColletionItem()行炸毁:

I'm attempting to use Steve Sanderson's blog post in order to edit a variable length list in my ASP MVC 3 view. The project builds fine, however whenever the partial view is rendered the program blows up on the using(Html.BeginColletionItem() line with this error:

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

完整的堆栈跟踪

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

管窥

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

查看

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

AgentRelationship codeS

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做。现在我比我paygrade,但是,因为我不知道该如何调试这样的事情。下面是抛 AccessViolationException 由WinDbg中的Visual Studio之前确定的例外。有被抛出的异常之间的信息很多,如果由任何人都需要的,请让我知道。

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

更新

通过选择项目的调试菜单中的本地code选项

By selecting the "Native Code" option in the project's Debuggers menu

我现在收到的的更详细的错误信息:

I now receive a slightly more detailed error message:

最后,通过切换到IIS防爆preSS的建议之下,我仍收到 AccessViolationException 。以下是我的设置用于启用IIS进行调试(在项目属性)

Lastly, by switching to IIS Express as suggested below I am still receiving the AccessViolationException. Here are the settings I used to enable IIS for debugging (under project properties)

下面是错误消息

调用堆栈:

推荐答案

在我看来,你的工作比你需要更加努力。

Seems to me that you're working harder than you need to.

首先,用一个取代的foreach for循环中,通过在索引元件到一个编辑器模板。这将建立在模板context。

First, replace the foreach with a for loop, passing the indexed element into an editor template. 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>

然后创建一个名为AgentRelationship codes.cshtml编辑模板(在查看/共享/ EditorTemplates)

Then create an editor template called AgentRelationshipCodes.cshtml (in 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>

和从NewRelationship code动作方法返回的字段集视图:

And return the fieldset view from your NewRelationshipCode action method:

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

这篇关于AccessViolationException了未处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-28 06:49
查看更多