简体   繁体   English

如何在未知模块上分析System.AccessViolationException

[英]How to Analyze System.AccessViolationException on Unknown Module

I have a MVC 4 project on Framework 4 with throws a System.AccessViolationException when you extend the HtmlHelper using HtmlHelper.ViewContext.Writer 我在Framework 4上有一个MVC 4项目,当您使用HtmlHelper.ViewContext.Writer扩展HtmlHelper时抛出System.AccessViolationException

The following code compiles just fine: 以下代码可以正常编译:

public static void Test(this System.Web.Mvc.HtmlHelper helper)
{
    System.IO.TextWriter writer = helper.ViewContext.Writer;
    writer.WriteLine("<b>Test Output</b>");
}

But when I use it in the view it throws the error. 但是,当我在视图中使用它时,会引发错误。 Now I've confirmed the DLL that causes the problem, but I have no idea what to look for, because the error message is not helpful, not even a stack trace. 现在,我已经确认了导致问题的DLL,但是我不知道要寻找什么,因为错误消息没有帮助,甚至没有堆栈跟踪。 The thing is the project was a MVC3 project written on VS2010, now that I updated to VS2013 and tried to upgrade to MVC4 the problem started, but the weird thing is that when I used the same DLL on other MVC4 projects in VS2010 on Framework 4, then it worked, now when I made a clean MVC4 project on Framework 4 this happens. 事情是项目是一个在VS2010上编写的MVC3项目,现在我更新到VS2013并试图升级到MVC4,问题开始了,但是奇怪的是,当我在Framework 4的VS2010中的其他MVC4项目上使用相同的DLL时,然后它起作用了,现在当我在Framework 4上创建一个干净的MVC4项目时,就会发生这种情况。

I know that the DLL in question is causing the problem and I do have the source code for it, but I have no idea what to look for. 我知道有问题的DLL引起了问题,我确实有它的源代码,但是我不知道要寻找什么。

I did test other extending methods and for example this works just fine: 我确实测试了其他扩展方法,例如,这很好用:

public static System.Web.Mvc.MvcHtmlString Test(this System.Web.Mvc.HtmlHelper helper)
{
    return new System.Web.Mvc.MvcHtmlString("<b>Test Output</b>");
}

So it has to do something with the ViewContext of the HtmlHelper , but what? 因此,它必须与HtmlHelperViewContext做些什么,但是呢?

The easiest thing would be to simply change the extending method, but do to company policy I'm not allowed to do that so I need to figure this out. 最简单的方法就是简单地更改扩展方法,但是对公司政策不行,所以我需要弄清楚这一点。

My biggest issue is that the DLL in question is not really written by me and only my computer has VS2013, so any direction would be helpful ie what to look for or anything like that. 我最大的问题是问题DLL不是我真正编写的,只有我的计算机具有VS2013,因此任何方向都将是有帮助的,即查找内容或类似内容。

So after a lot of trial and error I accidental deleted one of my main MVC DLL from the main project. 因此,经过大量的反复试验,我意外地从主项目中删除了我的一个主要MVC DLL。 So I used the NuGet to restore the MVC4 there. 因此,我使用NuGet在那里还原了MVC4。 Now I used the update to restore it and there you go... Solved. 现在,我使用更新来还原它,然后您就可以解决了。

The new MVC 4.0 version is 4.0.40804.0 If you are having the same problem as I did then simply update the MVC through NuGet and problem solved. 新的MVC 4.0版本是4.0.40804.0。如果您遇到的问题与我相同,则只需通过NuGet更新MVC即可解决问题。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM