473,782 Members | 2,699 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Object variable or With block variable not set

I am trying to deal with an image in code-behind. I consistently get the
following error:

Server Error in '/' Application.
Object variable or With block variable not set.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullRefe renceException: Object variable or
With block variable not set.

Source Error:

An unhandled exception was generated during the execution of the current
web request. Information regarding the origin and location of the
exception can be identified using the exception stack trace below.

Stack Trace:

[NullReferenceEx ception: Object variable or With block variable not set.]
Microsoft.Visua lBasic.Compiler Services.LateBi nding.LateGet(O bject o,
Type objType, String name, Object[] args, String[] paramnames, Boolean[]
CopyBack) +934
TeamMetz.Add30_ Preview(Object sender, EventArgs e) +73
System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e) +108

System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring
eventArgument) +57
System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +33
System.Web.UI.P age.ProcessRequ estMain() +1292
Version Information: Microsoft .NET Framework Version:1.1.432 2.2300;
ASP.NET Version:1.1.432 2.2300

What is happening is that I try to catch the image using the following:

Private Sub Add30_Preview(B yVal sender As Object, ByVal e As EventArgs)
Dim imgContent as Object = request.form("I mageUpLoad")
Dim imgStream as Stream
imgStream = imgContent.Post edFile.InputStr eam
It is clear that the error occurs at the last two lines, because if I
comment them out, everything goes fine (except that the images cannot be
"handled", and therefore do not come up in the preview).

TIA.
...Geshel
--
*************** *************** *************** *************** ***********
* My reply-to is an automatically monitored spam honeypot. Do not use *
* it unless you want to be blacklisted by SpamCop. Please reply to my *
* first name at my last name dot org. *
*************** *************** *************** *************** ***********
* “I contend that we are both atheists. I just believe in one fewer *
* god than you do. When you understand why you dismiss all the other *
* possible gods, you will understand why I dismiss yours.” *
* - Stephen F. Roberts *
*************** *************** *************** *************** ***********
* “Anyone who believes in Intelligent Design (“creationism ”) is just *
* as ignorant, irrational and ill-educated as someone who believes *
* that the world is a flat disc, that the Sun circles the Earth or *
* that there really is a tooth fairy. Darwinism has an overwhelming *
* foundation of evidence that can be tested and reproduced. *
* *
* “Intelligent Design, on the other hand, has no evidence at all;not *
* one single shred of testable proof. As such, Intelligent Design is *
* Religious Mythology, and has no right whatsoever to be in our *
* Science classrooms.” - 99.99+% of Scientists *
*************** *************** *************** *************** ***********
Mignon McLaughlin once said that “A nymphomaniac is a woman [who is] as
obsessed with sex as the average man.” Unfortunately, since true
nymphomaniacs are so rare, this means that it takes an extraordinary
woman to keep up with an ordinary man.
*************** *************** *************** *************** ***********
Mar 21 '06 #1
6 4263
Neo,

This is a class where is written "must inherit" so it cannot used as this,
beside that you have to instance a class as new. Would you not have to
overlook your code what was the base for this.

Cor

"Neo Geshel" <go****@geshel. org> schreef in bericht
news:ei******** *****@TK2MSFTNG P12.phx.gbl...
I am trying to deal with an image in code-behind. I consistently get the
following error:

Server Error in '/' Application.
Object variable or With block variable not set.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullRefe renceException: Object variable or
With block variable not set.

Source Error:

An unhandled exception was generated during the execution of the current
web request. Information regarding the origin and location of the
exception can be identified using the exception stack trace below.

Stack Trace:

[NullReferenceEx ception: Object variable or With block variable not set.]
Microsoft.Visua lBasic.Compiler Services.LateBi nding.LateGet(O bject o,
Type objType, String name, Object[] args, String[] paramnames, Boolean[]
CopyBack) +934
TeamMetz.Add30_ Preview(Object sender, EventArgs e) +73
System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e) +108

System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring
eventArgument) +57
System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +33
System.Web.UI.P age.ProcessRequ estMain() +1292
Version Information: Microsoft .NET Framework Version:1.1.432 2.2300;
ASP.NET Version:1.1.432 2.2300

What is happening is that I try to catch the image using the following:

Private Sub Add30_Preview(B yVal sender As Object, ByVal e As EventArgs)
Dim imgContent as Object = request.form("I mageUpLoad")
Dim imgStream as Stream
imgStream = imgContent.Post edFile.InputStr eam
It is clear that the error occurs at the last two lines, because if I
comment them out, everything goes fine (except that the images cannot be
"handled", and therefore do not come up in the preview).

TIA.
....Geshel
--
*************** *************** *************** *************** ***********
* My reply-to is an automatically monitored spam honeypot. Do not use *
* it unless you want to be blacklisted by SpamCop. Please reply to my *
* first name at my last name dot org. *
*************** *************** *************** *************** ***********
* "I contend that we are both atheists. I just believe in one fewer *
* god than you do. When you understand why you dismiss all the other *
* possible gods, you will understand why I dismiss yours." *
* - Stephen F. Roberts *
*************** *************** *************** *************** ***********
* "Anyone who believes in Intelligent Design ("creationis m") is just *
* as ignorant, irrational and ill-educated as someone who believes *
* that the world is a flat disc, that the Sun circles the Earth or *
* that there really is a tooth fairy. Darwinism has an overwhelming *
* foundation of evidence that can be tested and reproduced. *
* *
* "Intelligen t Design, on the other hand, has no evidence at all; not *
* one single shred of testable proof. As such, Intelligent Design is *
* Religious Mythology, and has no right whatsoever to be in our *
* Science classrooms." - 99.99+% of Scientists *
*************** *************** *************** *************** ***********
Mignon McLaughlin once said that "A nymphomaniac is a woman [who is] as
obsessed with sex as the average man." Unfortunately, since true
nymphomaniacs are so rare, this means that it takes an extraordinary
woman to keep up with an ordinary man.
*************** *************** *************** *************** ***********
Mar 22 '06 #2
Hi,
Private Sub Add30_Preview(B yVal sender As Object, ByVal e As EventArgs) 1. >> Dim imgContent as Object = request.form("I mageUpLoad")
2. >> Dim imgStream as Stream
3. >> imgStream = imgContent.Post edFile.InputStr eam
It is clear that the error occurs at the last two lines, because if I
comment them out, everything goes fine (except that the images cannot be
"handled", and therefore do not come up in the preview)
IMHO, It is the first line and not the last 2 lines that have the
problem.
The HttpPostedFile. InputStream method *does* return a System.IO.Strea m
object.

So, the problem in my view is how you are constructing your
HttpPostedFile object. Assuming that "request" is an HttpRequest
object, then it's Form property would return a NameValueCollec tion of
all the Form items. That is where you need to pay attention.

Cor wrote :
This is a class where is written "must inherit" so it cannot used as this,
beside that you have to instance a class as new.


Err... Cor, now I'm a little confused. I understand that a class that
is "MustInheri t" cannot be instantiated directly, (using the New
keyword), but I think that it can still hold an object of that type.

For instance, is this code wrong ? :-
---------------------------------------------------
Dim MyFile As HttpPostedFile
Dim MyStream As System.IO.Strea m

MyFileCollectio n = Request.Files
MyFile = MyFileCollectio n(0)

' Initialize the stream.
MyStream = MyFile.InputStr eam
---------------------------------------------------

Regards,

Cerebrus.

Mar 22 '06 #3
Cerebrus wrote:
Hi,
Private Sub Add30_Preview(B yVal sender As Object, ByVal e As EventArgs) 1. >> Dim imgContent as Object = request.form("I mageUpLoad")
2. >> Dim imgStream as Stream
3. >> imgStream = imgContent.Post edFile.InputStr eam
It is clear that the error occurs at the last two lines, because if I
comment them out, everything goes fine (except that the images cannotbe
"handled", and therefore do not come up in the preview)
IMHO, It is the first line and not the last 2 lines that have the
problem.
The HttpPostedFile. InputStream method *does* return a System.IO.Strea m
object.

So, the problem in my view is how you are constructing your
HttpPostedFile object. Assuming that "request" is an HttpRequest
object, then it's Form property would return a NameValueCollec tion of
all the Form items. That is where you need to pay attention.

Cor wrote :
This is a class where is written "must inherit" so it cannot used as this,
beside that you have to instance a class as new.


Err... Cor, now I'm a little confused. I understand that a class that
is "MustInheri t" cannot be instantiated directly, (using the New
keyword), but I think that it can still hold an object of that type.

For instance, is this code wrong ? :-
---------------------------------------------------
Dim MyFile As HttpPostedFile
Dim MyStream As System.IO.Strea m

MyFileCollectio n = Request.Files
MyFile = MyFileCollectio n(0)

' Initialize the stream.
MyStream = MyFile.InputStr eam
---------------------------------------------------

Regards,

Cerebrus.


When I try out your code snippet there, I get the following error:

Compiler Error Message: BC30002: Type 'HttpPostedFile ' is not defined.
Source Error:
Line 203: End Sub
Line 204: Private Sub Add30_Preview(B yVal sender As Object, ByVal e As
EventArgs)
Line 205:Dim MyFile As HttpPostedFile
Line 206:Dim imgStream As System.IO.Strea m
Line 207:

So it appears that no, the code is not correct.

TIA.
...Geshel
--
*************** *************** *************** *************** ***********
* My reply-to is an automatically monitored spam honeypot. Do not use *
* it unless you want to be blacklisted by SpamCop. Please reply to my *
* first name at my last name dot org. *
*************** *************** *************** *************** ***********
* “I contend that we are both atheists. I just believe in one fewer *
* god than you do. When you understand why you dismiss all the other *
* possible gods, you will understand why I dismiss yours.” *
* - Stephen F. Roberts *
*************** *************** *************** *************** ***********
* “Anyone who believes in Intelligent Design (“creationism ”) is just *
* as ignorant, irrational and ill-educated as someone who believes *
* that the world is a flat disc, that the Sun circles the Earth or *
* that there really is a tooth fairy. Darwinism has an overwhelming *
* foundation of evidence that can be tested and reproduced. *
* *
* “Intelligent Design, on the other hand, has no evidence at all;not *
* one single shred of testable proof. As such, Intelligent Design is *
* Religious Mythology, and has no right whatsoever to be in our *
* Science classrooms.” - 99.99+% of Scientists *
*************** *************** *************** *************** ***********
Mignon McLaughlin once said that “A nymphomaniac is a woman [who is] as
obsessed with sex as the average man.” Unfortunately, since true
nymphomaniacs are so rare, this means that it takes an extraordinary
woman to keep up with an ordinary man.
*************** *************** *************** *************** ***********
Mar 23 '06 #4
Cerebrus wrote:
For instance, is this code wrong ? :-
---------------------------------------------------
Dim MyFile As HttpPostedFile
Dim MyStream As System.IO.Strea m

MyFileCollectio n = Request.Files
MyFile = MyFileCollectio n(0)

' Initialize the stream.
MyStream = MyFile.InputStr eam
---------------------------------------------------

Regards,

Cerebrus.


As well, when I do the following:

Private Sub Add30_Preview(B yVal sender As Object, ByVal e As EventArgs)
If Nothing <> ImageUpLoad.Pos tedFile Then
Dim imgStream As Stream = ImageUpLoad.Pos tedFile.InputSt ream
Dim imgLen As Integer = ImageUpLoad.Pos tedFile.Content Length
Dim imgType as String =
ImageUpLoad.Pos tedFile.Content Type.ToString() .ToLower()
End If

I get the following error message:

Compiler Error Message: BC30451: Name 'ImageUpLoad' is not declared.
Source Error:
Line 203: End Sub
Line 204: Private Sub Add30_Preview(B yVal sender As Object, ByVal e As
EventArgs)
Line 205: If Nothing <> ImageUpLoad.Pos tedFile Then
Line 206: Dim imgStream As Stream = ImageUpLoad.Pos tedFile.InputSt ream
Line 207: Dim imgLen As Integer = ImageUpLoad.Pos tedFile.Content Length
The problem is, ImageUpLoad is properly declared in the code!! It is
properly declared as an HtmlInputFile in the Page_Load in the following
manner:

Dim imgupload As New HtmlInputFile
myForm.Controls .Add(imgupload)
imgupload.ID = "ImageUpLoa d"
imgupload.Accep t = "image/jpg"
Please Help!
TIA.
...Geshel
--
*************** *************** *************** *************** ***********
* My reply-to is an automatically monitored spam honeypot. Do not use *
* it unless you want to be blacklisted by SpamCop. Please reply to my *
* first name at my last name dot org. *
*************** *************** *************** *************** ***********
* “I contend that we are both atheists. I just believe in one fewer *
* god than you do. When you understand why you dismiss all the other *
* possible gods, you will understand why I dismiss yours.” *
* - Stephen F. Roberts *
*************** *************** *************** *************** ***********
* “Anyone who believes in Intelligent Design (“creationism ”) is just *
* as ignorant, irrational and ill-educated as someone who believes *
* that the world is a flat disc, that the Sun circles the Earth or *
* that there really is a tooth fairy. Darwinism has an overwhelming *
* foundation of evidence that can be tested and reproduced. *
* *
* “Intelligent Design, on the other hand, has no evidence at all;not *
* one single shred of testable proof. As such, Intelligent Design is *
* Religious Mythology, and has no right whatsoever to be in our *
* Science classrooms.” - 99.99+% of Scientists *
*************** *************** *************** *************** ***********
Mignon McLaughlin once said that “A nymphomaniac is a woman [who is] as
obsessed with sex as the average man.” Unfortunately, since true
nymphomaniacs are so rare, this means that it takes an extraordinary
woman to keep up with an ordinary man.
*************** *************** *************** *************** ***********
Mar 23 '06 #5
Neo wrote :
So it appears that no, the code is not correct.
TIA.
...Geshel
Actually not, Neo, since the code was copied from an MSDN page, so it
*is* correct. HttpPostedFile is not recognized probably since you need
to import the System.Web namespace. When I asked Cor Ligthert if the
code was *wrong*, I didn't mean syntactically wrong, I just meant
Logically wrong.
It is properly declared as an HtmlInputFile in the Page_Load...


There you have a problem ! Declare it outside of any method, so it will
be a global variable. Then you can instantiate it within the Load
method. Since you have declared it within the Page_Load method, it goes
out of context the moment the Page_Load method completes. Therefore,
when you reference it within another method, the compiler will ring the
alarm bells, saying the variable is not declared !

Outside any method :
-------------------------------
Dim imgupload As New HtmlInputFile

Within Page_Load method :
----------------------------------------
imgUpload = New HtmlInputFile ()

Now go ahead and use it in your Add30_Preview method.

HTH,

Regards,

Cerebrus.

Mar 23 '06 #6
BTW, that's one hell of a signature you've got !

Mar 23 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
6751
by: Hung Jung Lu | last post by:
Hi, Does anybody know where this term comes from? "First-class object" means "something passable as an argument in a function call", but I fail to see the connection with "object class" or with "first-class airplane ticket". I just find the name a bit strange. Also, if there are first-class objects, what would the second-class objects or economy/tourist class objects be? :)
10
1841
by: Michael McCracken | last post by:
Hi, I have a problem with unittest.TestCase that I could really use some help with. I have a class File in module File. The important thing about File for this discussion is that it's simple - no pool of objects are involved, and subsequent invocations of File.File('filename') should return distinct objects (and indeed, they do on the command line). Also, __repr__ prints out the value of id(self) for File, so I can tell what's going on...
8
1840
by: Mark Neilson | last post by:
1. What is the best way to make a single instance of my top level class (DLL) internally available to all other members of the assembly? The top level object is where all other access is made in to the program. Where and how do I declare and initialise this object? For instance, it would have property implementation like this: //******************************************* public MyClass1 Class1 {
6
1910
by: Neo Geshel | last post by:
I am trying to deal with an image in code-behind. I consistently get the following error: Server Error in '/' Application. Object variable or With block variable not set. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object variable...
44
3387
by: petermichaux | last post by:
Hi, I have been using the following line of code to create an object called "Serious" if it doesn't already exist. if (Serious == null) {var Serious = {};} This works in the scripts I use it but but www.jslint.com is not happy with me.
3
35513
by: Richard Hollenbeck | last post by:
I've marked the line in this subroutine where I've been getting this error. It may be something stupid but I've been staring at this error trying to fix it for over an hour. I'm pretty sure the table and field names and controls are all named correctly, and the control referred to in the errant code is open, and it has data in it. Private Sub cmdAddIngredientToRecipe_Click() ' Get RecipeID for future action query Dim recipeID As Long
1
2313
by: abhijmenbumca07 | last post by:
Object variable or With block variable not set. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object variable or With block variable not set. Source Error: Line 305: Me.txt_amount.Text = mat(0) Line 306: ...
4
3478
by: BrianAdev | last post by:
Why It throw an error of <Object variable or With block variable not set> set objAccess = GetObject(strMdbPath) objAccess.DoCmd.SetWarning False objAccess.DoCmd.OpenReport strReportName, 0 'It is fine until now objAccess.Application.Run "Function",Arg1,Arg2 'Throw the arror <Object variable or With block variable not set>
3
3261
by: Newbie19 | last post by:
I'm trying to get a list of all subfolders in a folder on a share drive, but I keep on getting this error message: Object variable or With block variable not set. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object variable or With block...
0
9639
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10308
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10143
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8964
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7486
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6729
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5375
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4040
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.