使用带有ip的iis时,对象引用未设置为对象的实例 [英] Object reference not set to an instance of an object when use iis with ip

查看:148
本文介绍了使用带有ip的iis时,对象引用未设置为对象的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在asp.net中编写代码和页面

当我在localhost中运行时它运行良好但是当我将它设置为iis(我的电脑中的本地iis不在主机上)并设置本地ip为它,它告诉我这个错误



对象引用未设置为对象的实例



i write code and page in asp.net
when i run it in localhost it's worked well but when i set it to iis (local iis in my pc not on host) and set local ip for it , it's show me this error

Object reference not set to an instance of an object

Line 36:         //j2.[2], 
Line 37:         string model1 = "";
Line 38:         for (int i = 0; i < dt_colfield.Rows.Count; i++)
Line 39:         {
Line 40:             if (!string.IsNullOrEmpty(dt_colfield.Rows[i][0].ToString()))





我怎么修理它?我的问题是关于iis而不是代码因为它在localhost中工作得很好



how i fix it ? my problem is on iis not the code bacause it's worked well in localhost

推荐答案

我们无法确切地告诉你为什么会出现问题 - 这可能是实际的错误在你的代码的其他地方,只出现在这里。

但基本上,正在发生的是。左边的一个元素。是 null

例如:

We can't tell you exactly why you get the problem - it's likely that the actual fault is elsewhere in your code and is only showing up here.
But basically, what is happening is that one of the elements to the left of a "." is null.
For example:
string s = a.b.c.d.ToString();

如果 a null ,你会收到错误。

如果 a 是一个值,但 ab null ,您将收到错误。

如果 ab 是一个值,但是 abc null ...



你得到这个想法。



在给出错误的线上方的线上放置一个断点并使用鼠标依次悬停在每个部分上 - 找到哪一个 null 你可以开始寻找你的代码让它为空的原因。


对不起,但它已经结束了和调试器,我很害怕。

if a is null, you will get the error.
if a is a value, but a.b is null, you will get the error.
if a.b is a value, but a.b.c is null...

You get the idea.

Put a breakpoint on the line above the one giving the error and use the mouse to hover over each part in turn - find which one is null and you can start looking for why your code has let it be null.

Sorry, but it's over to you and the debugger, I'm afraid.


这篇关于使用带有ip的iis时,对象引用未设置为对象的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆