System.NullReference Exception occurred in App_Web_XXX.dll - Error in Partial View

流过昼夜 提交于 2019-12-23 10:05:20

问题


I'm getting this error, with a random string in the dll name, when landing on one of my MVC pages.

A first chance exception of type System.NullReferenceException occurred in App_Web_cjmhrrqn.dll. Additional information: Object reference not set to an instance of an object.

on another page, I get similar when hitting the first line of code on the page, not matter what it is:

A first chance exception of type System.NullReferenceException occurred in App_Web_register.cshtml.5f83eb8c.gq-8jyy8.dll

However, this is not a problem with the code. I've removed the lines it fails at and it continues to fail at the next line of code. I can even put several lines of new code and it will break at the last one.

It happens in a couple of places throughout the application.

It also happens on my Azure deployment.

The error does not help in any way to find the problem.

My suspicion is some kind of DLL issue but I have cleared out my bin, obj, and ASP.NET temporary folders.

Has anyone seen this issue, or have any ideas? Are there any other temporary folders I need to clear? Or any other way to mitigate this issue? How come it is still on my live site too?


回答1:


OK so guess what...it WAS a problem with the code.

The problem was that there was an issue in the Partial view. I was trying to use Model.SomethingNull without checking it.

The lesson to be learnt here though (apart from check for null!) is that when there is an issue like this in a partial view which you are calling using Html.Partial, Visual Studio won't step through the lines of the Partial view. It will just fail at the start of the partial and won't tell you that there is a problem somewhere in it.

This also explains why the problem was present in all environments.




回答2:


I'm new to Stack Overfow so I can't ask questions yet - otherwise I would...but, is your App_Web_xxx.dll for a WCF web service that is being called by your MVC app? If it is, I've had this same issue in projects where Visual Studio flakes out when creating the temporary DLL for the web service. A workaround that has worked for me was to use svcutil to create a .cs file for the web service (And you'd deploy that .cs file in the App_Code directory of your website) - syntax for svcutil is similar to:

svcutil /t:code yourwebserviceurl /out:c:\temp\yourservicename.cs /config:c:\temp\yourservicename.config

(where "yourwebserviceurl" is the URL and "yourservicename" is whatever you want your cs file to be named)

If this isn't a web service, well, disregard my answer...I'd rather it be a question to you!




回答3:


I faced this error but for a different reason.

In the controller i was returning

return View();

instead of

return View(modelInstance);

while I was using the @Model.<<modelInstance's property>> in the View



来源:https://stackoverflow.com/questions/23539036/system-nullreference-exception-occurred-in-app-web-xxx-dll-error-in-partial-vi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!