AccessViolationException was unhandled
Asked Answered
P

1

10

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

enter image description here

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

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

UPDATE

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

enter image description here

I now receive a slightly more detailed error message:

enter image description here

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)

enter image description here

Here is the error message

enter image description here

Call stack:

enter image description here

Penguin answered 2/5, 2014 at 22:16 Comment(20)
AccessViolationException means an unmanaged component (basically any native DLL... for example virtualbox.org/ticket/9317) used by ProcessRequest internally failed. You need to attach with a debugger than can dump native frames, for example WinDbg, to determine the root cause of the problem, at least find a suspect DLL .Kunlun
Try removing references and use nugget insteadTonl
Do you have any VS/Code 3rd party tools installed?Forth
if you van get his demo project to run then you know it is a bug from outside that piece of code. look at unmanaged dlls (web gl maybe?)Pros
Showing us the AgentRelationshipCodes model would probably help, specifically the constructor.Pubis
@PaulZahra - just added the model to the postPenguin
What if you use IIS / IIS Express instead of Visual Studio Development Server?Impoverish
Sir please have a look at this linkUncharted
The unmanaged code is causing this exceptionUncharted
@SimonMourier - how do I use WinDbg for this purpose? Updated the post with the error it's spitting out once the AccessViolationException occurs.Penguin
You need to google on Windbg and "SOS", for example: netmatze.wordpress.com/2012/08/24/…Kunlun
As haim770 said, you should use IIS Express instead of Cassini. I would bet money the problem goes away.Athelstan
@ErikPhilips - just updated the post. I switched to IIS and received the same error message.Penguin
@Penguin I'm not sure how that can be the case as I'm 99.99% sure that Cassini is the ONLY program that uses WebDev.WebHost40.dll. Are you getting the same exception in the same assembly/dll?Athelstan
@ErikPhilips - I'm not sure if it's the same .dll but it is the same exception. Just added the error message to my post.Penguin
Can you include a stack trace? Are you using ANY assemblies/dlls from 3rd parties (anything not directly from microsoft). Your specific Error is 0x80004003 E_Pointer - Pointer that is not valid.Athelstan
@ErikPhilips - I'm not sure how to get a stack trace for this. The closest I've come are the messages in the first EDIT from WinDbg. This is an MVC app that is using the BeginCollectionItem plugin in a parital view. The error is thrown on the using statment for this plugin in the view. If I can figure out how to get a stack trace from there I will post it. And yes, I am using a couple 3rd party plugins: EPPlus, Automapper, and BeginCollectionItemPenguin
@ErikPhilips - Sorry, forgot the Exceptions StackTrace was available in the post already.Penguin
Let us continue this discussion in chat.Athelstan
Is there a reason for using the "NullableDate" rendering object, when rendering the string property "RelationshipId"?Marianmariana
L
1

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

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

[HandleProcessCorruptedStateExceptions]
public ViewResult NewRelationshipCode(YourViewModel model)
{
    model.AgentRelationshipCodes.Add(new AgentRelationshipCodes());
    return View("fieldset", model);
}
Lajuanalake answered 30/12, 2014 at 20:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.