Object reference not set to an instance of an object. http://forums.asp.net/t/1555610.aspx/1?Object+reference+not+set+to+an+instance+of+an+object+Tue, 11 May 2010 15:03:12 -040015556103824051http://forums.asp.net/p/1555610/3824051.aspx/1?Object+reference+not+set+to+an+instance+of+an+object+Object reference not set to an instance of an object. <p>I just downloaded&nbsp;and installed the starter kit. Then I&nbsp;attached the database to my SQL server and commented the&nbsp;classifiedsConnection in the connection strings in web.config and added a new classifiedsConnection with the connection infor to&nbsp;the restored database. Then when I ran the web site, it opened the site without any issues. When I click on the login link, it gave me the following error. &nbsp;</p> <p>Object reference not set to an instance of an object.</p> <p>Now even when I stop and restart the site in VS2005 it keeps giving me the above error at the following line of code.</p> <p>Line 23:&nbsp;&nbsp;&nbsp;&nbsp; Protected Sub PasswordRecovery_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles PasswordRecovery.Init<br> Line 24:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim s As SiteSettings = SiteSettings.GetSharedSettings()<br> <font color="#ff0000">Line 25:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PasswordRecovery.MailDefinition.From = s.SiteEmailFromField<br> </font>Line 26:&nbsp;&nbsp;&nbsp;&nbsp; End Sub<br> Line 27:</p> <p>&nbsp;</p> <p>When I checked the contents in the debug mode, I do see values for variable s, but it keeps giving me the error. Also in debug mode it stops at the above line and displays &quot;Use the New keywork to create an object instance&quot;</p> <p>I am not sure how to fix this. I am using SQL 2005 with VS 2005.</p> <p>Any help is greatly appreciated.</p> 2010-05-07T18:31:31-04:003824118http://forums.asp.net/p/1555610/3824118.aspx/1?Re+Object+reference+not+set+to+an+instance+of+an+object+Re: Object reference not set to an instance of an object. <p>MailDefinition is a class.&nbsp; You need to instantiate it before working with it.&nbsp; So I suspect that MailDefinition is null&nbsp;and you're trying to access the From property on a null object.</p> 2010-05-07T19:34:00-04:003824124http://forums.asp.net/p/1555610/3824124.aspx/1?Re+Object+reference+not+set+to+an+instance+of+an+object+Re: Object reference not set to an instance of an object. <p>But when I checked the value it&nbsp;was empty,&nbsp;even though variable s has something, the error is coming because of that variable and I cannot use new keywork there.&nbsp;</p> 2010-05-07T19:37:35-04:003824127http://forums.asp.net/p/1555610/3824127.aspx/1?Re+Object+reference+not+set+to+an+instance+of+an+object+Re: Object reference not set to an instance of an object. <p></p> <blockquote><span class="icon-blockquote"></span> <h4>coolvaas1</h4> <p>But when I checked the value it&nbsp;was empty,&nbsp;even though variable s has something, the error is coming because of that variable and I cannot use new keywork there.&nbsp;</p> <p></p> </blockquote> &nbsp; <p></p> <p>You seem to be hung up on the s variable.&nbsp; Read what I posted before carefully.&nbsp; And to confirm what I said, or prove me wrong, put a breakpoint and hover over MailDefinition.&nbsp; I'll bet, a shiny penny, that it's null.</p> 2010-05-07T19:42:03-04:003824132http://forums.asp.net/p/1555610/3824132.aspx/1?Re+Object+reference+not+set+to+an+instance+of+an+object+Re: Object reference not set to an instance of an object. <p>Going with above poster,</p> <p>That error comes when you perform any operation on a object which is null. For example suppose if you are doing obj.ToString() and if obj is null then that error will come , so please debug your code and debug line by line and see where it is causing that error and see on that line an object on which you would be performing any operation will be set as null.</p> 2010-05-07T19:47:31-04:003825280http://forums.asp.net/p/1555610/3825280.aspx/1?Re+Object+reference+not+set+to+an+instance+of+an+object+Re: Object reference not set to an instance of an object. <p>Have you run ASPNet Configuration from the website tab in visual web developer &nbsp;</p> 2010-05-08T17:21:30-04:003827794http://forums.asp.net/p/1555610/3827794.aspx/1?Re+Object+reference+not+set+to+an+instance+of+an+object+Re: Object reference not set to an instance of an object. <p>Ok, I put a breakpoint at PasswordRecovery.MailDefinition.From = s.SiteEmailFromField</p> <p>And the PasswordRecovery.MailDefinition.From value is blank</p> <p>When I check the value in s.SiteEmailFromField, I get / see the 'Referenced object has a value of 'Nothing''</p> <p>So to confirm it, at the breakpoint I entered the following.</p> <p>PasswordRecovery.MailDefinition.From =&quot;test&quot;</p> <p>And the above statement works (no errors). So I don't believe the error is with MailDefinition class.</p> <p>&nbsp;</p> 2010-05-10T14:34:42-04:003828150http://forums.asp.net/p/1555610/3828150.aspx/1?Re+Object+reference+not+set+to+an+instance+of+an+object+Re: Object reference not set to an instance of an object. <p>I moved the enrite site to another pc that has SQL express installed and everything is working fine on that pc. Not sure why it's not working on my other pc with a remote SQL database.&nbsp;But for now&nbsp;I consider this as resolved.</p> <p>Thanks for all your feedbacks.&nbsp;</p> 2010-05-10T18:41:35-04:003828478http://forums.asp.net/p/1555610/3828478.aspx/1?Re+Object+reference+not+set+to+an+instance+of+an+object+Re: Object reference not set to an instance of an object. <p>SQL Server by default wont allow &quot;Remote Connections&quot; off its internal network.</p> <p>If you are using a hosting provider it is unlikely that you can change this setting because of&nbsp;vulnerability of attacks that can corrupt there systems or your data, how ever there are some providers who have taken extra&nbsp;measures to protect against such attacks and may have the option to allow remote connections.</p> <p>If it is a functionality you NEED then contacting your provider is my&nbsp;recommendation.</p> 2010-05-10T23:42:18-04:003830087http://forums.asp.net/p/1555610/3830087.aspx/1?Re+Object+reference+not+set+to+an+instance+of+an+object+Re: Object reference not set to an instance of an object. <p>Actually I have other web applications that connect to the SQL server. So the remote connections are on.&nbsp;</p> 2010-05-11T15:03:12-04:00