App.Web_XXX.dll中发生System.NullReference异常 - 部分视图中出错

时间:2022-03-07 16:54:37

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

当我登陆我的一个MVC页面时,我收到此错误,在dll名称中有一个随机字符串。

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.

App_Web_cjmhrrqn.dll中发生System.NullReferenceException类型的第一次机会异常。附加信息:对象引用未设置为对象的实例。

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

App_Web_register.cshtml.5f83eb8c.gq-8jyy8.dll中发生System.NullReferenceException类型的第一次机会异常

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.

它也发生在我的Azure部署上。

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.

我的怀疑是某种DLL问题,但我已经清除了我的bin,obj和ASP.NET临时文件夹。

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?

有谁见过这个问题,还是有什么想法?我需要清除其他任何临时文件夹吗?或者任何其他方法来缓解这个问题?为什么它仍然在我的现场网站上呢?

3 个解决方案

#1


2  

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.

问题是部分视图中存在问题。我试图使用Model.SomethingNull而不检查它。

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.

这里要学到的教训(除了检查空!)是在使用Html.Partial调用的局部视图中存在这样的问题时,Visual Studio将不会单步执行部分视图的行。它只会在部分开始时失败,并且不会告诉你它内部存在问题。

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

这也解释了为什么所有环境都存在问题。

#2


0  

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:

我是Stack Overfow的新手,所以我还不能提出问题 - 否则我会...但是,你的App_Web_xxx.dll是否适用于你的MVC应用调用的WCF Web服务?如果是这样,我在Visual Studio在为Web服务创建临时DLL时脱落的项目中遇到了同样的问题。对我有用的解决方法是使用svcutil为Web服务创建.cs文件(并在网站的App_Code目录中部署.cs文件) - svcutil的语法类似于:

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

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)

(其中“yourwebserviceurl”是URL,“yourservicename”是您想要命名的cs文件)

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

如果这不是一个网络服务,那么,请忽略我的答案......我宁愿这是一个问题给你!

#3


0  

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

我在View中使用了@Model。<< modelInstance的属性>>

#1


2  

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.

问题是部分视图中存在问题。我试图使用Model.SomethingNull而不检查它。

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.

这里要学到的教训(除了检查空!)是在使用Html.Partial调用的局部视图中存在这样的问题时,Visual Studio将不会单步执行部分视图的行。它只会在部分开始时失败,并且不会告诉你它内部存在问题。

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

这也解释了为什么所有环境都存在问题。

#2


0  

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:

我是Stack Overfow的新手,所以我还不能提出问题 - 否则我会...但是,你的App_Web_xxx.dll是否适用于你的MVC应用调用的WCF Web服务?如果是这样,我在Visual Studio在为Web服务创建临时DLL时脱落的项目中遇到了同样的问题。对我有用的解决方法是使用svcutil为Web服务创建.cs文件(并在网站的App_Code目录中部署.cs文件) - svcutil的语法类似于:

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

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)

(其中“yourwebserviceurl”是URL,“yourservicename”是您想要命名的cs文件)

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

如果这不是一个网络服务,那么,请忽略我的答案......我宁愿这是一个问题给你!

#3


0  

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

我在View中使用了@Model。<< modelInstance的属性>>