.NET Framework - Object reference not set to an instance of an object

Asked By dancer on 27-May-07 09:38 AM
Using VB.net and ASP.net

At runtime I receive the error that MANY people receive who are using much
more complicated code than mine.


I know WHY it's happening.  It is when a selection is not made to a
RadioButtonList, so the item is = to nothing.

I have a RequiredFieldValidator, but the runtime error obviously shows
before the validator can act.

The advice given on this error is that "You are trying to use a reference
variable whose value is Nothing"

How can I make the RequiredFieldValidator work BEFORE this runtime error
occurs?




Alexey Smirnov replied on 27-May-07 10:20 AM
What's your code for validator? Have you set the ControlToValidate?

some code that should work

RepeatLayout="Flow" runat="server">

ControlToValidate="ccType" ErrorMessage="Card Type. "
Display="Static" InitialValue="" Font-Names="Verdana" Font-Size="12"
runat="server">
*
dancer replied on 27-May-07 10:52 AM
My validator code is ok.  I copied it to another file, and it worked fine.
Are you game to look at the rest of my code?  If so, I will copy it here.

Thanks
Alexey Smirnov replied on 27-May-07 11:07 AM
Is it the same as in your previous post?
http://groups.google.com/group/microsoft.public.dotnet.framework.aspnet/browse_thread/thread/945034592e203207

add a RequiredFieldValidator for the EmpCaution

otherwise send me a code, I will check it, no problem :-)
dancer replied on 27-May-07 11:31 AM
Yes.  I just looked at your reply there:

list "

I don't have a RequiredFieldValidator for that or some others, because I'm
limiting my testing.  The less code I have, the less to confuse me.  I
always enter a selection for those radiobutton lists when testing the
EmpTrain list.   I get the runtime error ONLY when I don't enter a selection
for those OR for the EmpTrain list [even though the EmpTrain list has a
validator]

Did that paragraph make any sense?

Thank you.  If you can find any reason for the error, I will be eternally
grateful!
Alexey Smirnov replied on 27-May-07 01:19 PM
Using ClientTarget="downlevel" you render old browsers-compatible code
without javascript validation and any other client-side server control
functionality. Get rid of the ClientTarget and validation will work
again.

ASP.NET Web Server Controls and Browser Capabilities
http://msdn2.microsoft.com/en-us/library/x3k2ssx2.aspx
dancer replied on 27-May-07 03:36 PM
WHAT A RELIEF!!!
Thank you Alexey!!!    It works on my local computer, BUT  when I download
it to my server, it won't even let me see the page.  I get this message:

Runtime Error
Description: An application error occurred on the server. The current custom
error settings for this application prevent the details of the application
error from being viewed remotely (for security reasons). It could, however,
be viewed by browsers running on the local server machine.

Details: To enable the details of this specific error message to be viewable
on remote machines, please create a <customErrors> tag within a "web.config"
configuration file located in the root directory of the current web
application. This <customErrors> tag should then have its "mode" attribute
set to "Off".



Notes: The current error page you are seeing can be replaced by a custom
error page by modifying the "defaultRedirect" attribute of the application's
Alexey Smirnov replied on 27-May-07 03:59 PM
Great, glad you fixed it.



Go to the web.config file on your server and change customErrors to
Off


You should see a real error message then.
Alexey Smirnov replied on 27-May-07 04:21 PM
A RadioButton (RadioButtonList) will give you a single value selection.
dancer replied on 29-May-07 09:32 AM
But I want to be sure he checks one or both.  I understand that you cannot
use a validator with a radio button.
Also I get an error if  it is not checked.

??
Alexey Smirnov replied on 29-May-07 10:10 AM
??

You said "I ***do not*** want the user to be able to check both
employee and non-employee"


So, is it possible to be an Employee and Non-Employee in the same
time?
dancer replied on 29-May-07 02:11 PM
I think I was taking a nap when I wrote that. I MEANT to say I WANT the user
to check either one or both.
It is possible that 2 people are hurt in the same accident - one an employee
and the other a non-employee.
Alexey Smirnov replied on 29-May-07 02:40 PM
So, is it working now, or you still need a help? :-)

Let me know
Alexey Smirnov replied on 29-May-07 03:52 PM
The code looks correct. Try to check the values before

Response.Write(Checkemp.Checked)
Response.Write(Checknon.Checked)
dancer replied on 29-May-07 04:33 PM
My logic is working.
Now, how do I make sure the user checks one or other or both?
If I validate each text box it will make him answer both, even if it is only
one.

Thanks
Alexey Smirnov replied on 29-May-07 04:45 PM
If you have a question regarding code, you have to send that code.

I do not see your validation rule, how can I answer? :-)
dancer replied on 29-May-07 05:37 PM
I do not have code for that yet.  It is a question of concept.  Is there a
control to verify that if one check box is not checked, then the other is?

Thank you
dancer replied on 29-May-07 06:03 PM
Sorry to be so dumb, but how do I get to web.config file on my server?

Thanks you
Alexey Smirnov replied on 29-May-07 06:17 PM
You should have a local copy of it, make a change and copy back (e.g. via
FTP)
dancer replied on 29-May-07 06:59 PM
I am communicating with my server by FrontPage, not ftp.
I called my server and asked, "How do I get to the web.config file?"
He answered, "What's that?"
dancer replied on 29-May-07 07:03 PM
WHAT A HELP YOU ARE ALEXEY!!!
Could you also tell me how to make the Response.Write write in red?
The validator response text is all in red, but I didn't tell it to be in
red.  Is this a default for all validator text, or am I missing something?
Alexey Smirnov replied on 29-May-07 07:30 PM
Huh, a FrontPage? I'm not sure how it is working there, but as far as
I remember it has a site browser with all the files, I'm right? The
main web.config file is located in the root directory of your web
site. A web.config file could be located also in a sub-directories of
an application, but I think you don't use such case. So, look in the
root. If you have one, open it in FrontPage or copy a new one from
your local box.

How To Create the Web.config File for an ASP.NET Application
http://support.microsoft.com/kb/815179
dancer replied on 31-May-07 01:27 PM
Hi Alexey,
There was not a web.config file on my web at the server.  They created one.
Now I get errors which are no problem on my own computer.
I notice that at the end of the errors page is this:

Version Information: Microsoft .NET Framework Version:1.1.4322.2379; ASP.NET
Version:1.1.4322.2379

While on MY computer there is this:

Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET
Version:2.0.50727.210

Would that have anything to do with it?
If so, what can I do?
Juan T. Llibre replied on 31-May-07 01:37 PM
That error message means that, at the server, the application is running
against the .Net Framework 1.1, while at your computer it's running
against the .Net Framework 2.0.

You will need to set the application to run against
the .Net Framework 1.1 and your problems will go away.

Open the IIS Manager, right click the application, and select the "ASP.NET" tab;
then, select the .Net Framework 1.1 from the dropdown and OK your way out.

Stop and restart IIS ( from a "Run", cmd ) : iisreset

...and everything should work fine.




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
Juan T. Llibre replied on 31-May-07 01:40 PM
re:
!> You will need to set the application to run against
!> the .Net Framework 1.1 and your problems will go away.

Oops... that's backwards.

You will need to set the application, at the server, to run against
the .Net Framework 2.0 and your problems will go away.

Open the server's IIS Manager, right click the application, and select the "ASP.NET" tab;
then, select the .Net Framework 2.0 from the dropdown and OK your way out.

Stop and restart the server's IIS ( from a "Run", cmd ) : iisreset

...and everything should work fine.

Sorry about the instruction reversal.






Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
dancer replied on 31-May-07 01:44 PM
Here is an error that comes up on the server.  But this line compiles fine
on my computer
Compilation Error
Description: An error occurred during the compilation of a resource required
to service this request. Please review the following specific error details
and modify your source code appropriately.

Compiler Error Message: BC30456: 'Text' is not a member of
'System.Web.UI.WebControls.CheckBoxList'.

Source Error:


Line 28:   Dim TheNature    As String = nature.Text
Line 29:   Dim TheNatureNew As String
Line 30:   Dim TheIndicate  As String = Indicate.Text
Line 31:   Dim TheAction    As String = action.Text
Line 32:   Dim TheActionNew As String

Source File: e:\accounts\whee13\WWW\juan_radio32.aspx    Line: 30



Show Detailed Compiler Output:

c:\windows\system32\inetsrv>
/utf8output
/R:"c:\windows\assembly\gac\system.enterpriseservices\1.0.5000.0__b03f5f7f11d50a3a\system.enterpriseservices.dll"
/R:"c:\windows\assembly\gac\system.data\1.0.5000.0__b77a5c561934e089\system.data.dll"
/R:"c:\windows\assembly\gac\system.drawing\1.0.5000.0__b03f5f7f11d50a3a\system.drawing.dll"
/R:"c:\windows\assembly\gac\system.web.mobile\1.0.5000.0__b03f5f7f11d50a3a\system.web.mobile.dll"
/R:"c:\windows\assembly\gac\system.xml\1.0.5000.0__b77a5c561934e089\system.xml.dll"
/R:"c:\windows\assembly\gac\system.web.services\1.0.5000.0__b03f5f7f11d50a3a\system.web.services.dll"
/R:"c:\windows\assembly\gac\system\1.0.5000.0__b77a5c561934e089\system.dll"
/R:"c:\windows\assembly\gac\system.web\1.0.5000.0__b03f5f7f11d50a3a\system.web.dll"
/out:"C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET
Files\root\abc4b73d\d202bb95\r8nbr8x9.dll" /debug-
/win32resource:"C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Temporary
ASP.NET Files\root\abc4b73d\d202bb95\r8nbr8x9.res"
Files\root\abc4b73d\d202bb95\r8nbr8x9.0.vb"


Microsoft (R) Visual Basic .NET Compiler version 7.10.7017.4
for Microsoft (R) .NET Framework version 1.1.4322.2379
Copyright (C) Microsoft Corporation 1987-2002. All rights reserved.

e:\accounts\whee13\WWW\juan_radio32.aspx(30) : error BC30456: 'Text' is not
a member of 'System.Web.UI.WebControls.CheckBoxList'.

Dim TheIndicate  As String = Indicate.Text
~~~~~~~~~~~~~



Also this was one of many lines under "complete compilation source"
Line 268:          Protected Indicate As
System.Web.UI.WebControls.CheckBoxList

Thanks!
Alexey Smirnov replied on 31-May-07 02:03 PM
CheckBox Control has no Text property in .NET 1.0-1.1
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.checkboxlist_members(vs.71).aspx
dancer replied on 01-Jun-07 11:02 AM
I am so irritated!  My server - which is BellSouth.net - which is now AT&T -
does not have .Net Framework 2.0 installed.
Are they not WAY behind??!!

If I go backward, will much of my code have to be re-written?

Thank you.
Alexey Smirnov replied on 01-Jun-07 02:35 PM
maybe it simply not yet configured for your web site?
Juan T. Llibre replied on 01-Jun-07 03:05 PM
re:
!> If I go backward, will much of my code have to be re-written?

Any code which runs against 2.0-specific objects will fail.

Do *you* have the .Net Framework 1.1 installed ?

If you do, the best way to know whether your code will run is to install
the Web Matrix ( http://www.asp.net/webmatrix/ ) which has a
development web server, just like Visual Studio and VWD have.

It's only a 1.3MB download.

If the code runs within the Web Matrix development server, you're good to go.

If not, you can make the needed changes right in the
Web Matrix IDE, so your code *will* run against ASP.NET 1.1.

Of course, you can also ask your AT&T ISP whether they can support ASP.NET 2.0.
I'd find it really odd if they did not support ASP.NET 2.0.




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
dancer replied on 01-Jun-07 03:38 PM
This is what they say.
Unfortunately we are unable to fulfill this request. We do upgrade our
software as soon as possible, however, it does require that we go through a
rigorous certification process first, to make sure that the new software
does not conflict with any of the other software we have running, or our
site management software. As soon as we are able to certify the newest
version of the .NET framework, we will be upgrading the software on the
servers to fully support it.

And this:

Dear Valued Customer:

Currently our admins do not ahave a time table on when testing for upgrading
to the new .NET Framework will be started.
dancer replied on 01-Jun-07 04:02 PM
They support  Asp.net 1.1 only.  I already know my code fails on the server.
There do not seem to be any tutorials on 1.1, only 2.0
Does the Web Matrix tell you HOW to make the changes?
dancer replied on 01-Jun-07 09:28 PM
After having the webmatrix  page check to see if I had the proper Net
Framework installed, I installed Web Matrix Project. I read on the "getting
started" page of the Walk Through ".NET Framework Version 1.0.3705.0"

But when I made my first little page and ran it, I got an error and this
version at the bottom:

Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET
Version:2.0.50727.210

I was very careful to choose "Use ASP.NET Web Matrix Server" when I told it
to run.

I thought Net Framework 1.1 had been installed before on my computer. But  I
could not find it in the Administrative Tools - only 2.0.
So I downloaded it and answered Yes to install.
It still is not in the Administrative Tools.
I did a search and there is a Net Framework 1.1 config and 1.1 wizard in the
Administrator\Corp\Start Menu\Programs\ Administrative Tools only.

Where would it be and how do I get it to where I need it?
Juan T. Llibre replied on 01-Jun-07 10:45 PM
re:
!> I did a search and there is a Net Framework 1.1 config and 1.1 wizard in the
!> Administrator\Corp\Start Menu\Programs\ Administrative Tools only.

You have it installed, then.
You don't need to run those, except for very special needs.

After installing the .Net Framework 1.1, the Web Matrix's
dev server should be able to run your 1.1 pages.

You don't have to change the .Net Framework version for the app to 1.1
if you're going to use the development server built into the Web Matrix but,
to be on the safe side with IIS, switch the .Net Framework version for your app to 1.1.

Right-click the app in the IIS Manager, select "Properties" and then
select the "ASP.NET" tab; then switch the version  from the dropdown.

That way, you can double-check the code in IIS, too.

As far as Web Matrix goes, just copy/paste your current app's
pages into the Web Matrix IDE, one by one, and run them.

If there's anything specific to the .Net Framework 2.0,
it will throw an error and you can change the code or the object.







Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
dancer replied on 04-Jun-07 05:27 PM
I have downloaded and installed Net Framework 1.1 yet again.
I removed Web Matrix from my computer, downloaded it again and installed it
again.
When I open the program, the first page, as it is opening, says Net
Framework 2.
When I run a little program with an error in it, the compiler says
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET
Version:2.0.50727.210
?????
Alexey Smirnov replied on 05-Jun-07 03:39 PM
It means you have .NET 2.0 installed and configured for the web site.

What's the problem?
dancer replied on 05-Jun-07 07:07 PM
I had created a file using ASP.net 2.0.  It ran against (or with) Framework
2.0 on my computer.  It compiled and ran fine.
I transferred it to my hosting server and got errors.
I then found out that my hosting server supports only Framework 1.1 and
ASP.net 1.1.
Juan Libre recommended that I download WebMatrix Project, which runs with
1.1 to see where my code needed to be changed to be compatible wth my
hosting server.
BUT it keeps saying 2.0, so how can I make changes for 1.1?
Juan T. Llibre replied on 05-Jun-07 07:53 PM
re:
!> Juan Libre recommended that I download WebMatrix Project, which runs with
!> 1.1 to see where my code needed to be changed to be compatible wth my hosting server.
!> BUT it keeps saying 2.0, so how can I make changes for 1.1?

Do you have the .Net Framework 1.1 installed in your home computer ?
( whereever you are doing the development work... )

If not, you need to install it.

If the .Net Framework 1.1 isn't installed, download it from :
http://www.microsoft.com/downloads/details.aspx?FamilyID=262d25e3-f589-4842-8157-034d1e7cf3a3&DisplayLang=en

...and install it ( 23MB download ).

As soon as you install it, download the .Net Framework Service Pack 1 :
http://www.microsoft.com/downloads/details.aspx?familyid=A8F5654F-088E-40B2-BBDB-A83353618B38&displaylang=en

...and install *that*.

After you've installed them both you should see an ASP.NET tab
in the IIS Manager, when you right-click your application.

Click the tab...and change the ASP.NET version to 1.1.4322.

Your problems will be on the way to being solved at that point.

You may still have object problems, but you can code your way
around them by reading the error messages and changing the code.




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================