I'm getting a System.StackOverflowException, and I can't see why.
Here's the code that's throwing the exception. I don't see anyting
that's recursive about it. Any help is appreciated (including help in
debugging - I'm not sure what I'd put in a try or catch clause here):
DataDealings sql = new DataDealings();
myProject = sql.GetProject(pID);
-------------------------------------------------------------------------------------
public Project GetProject (int pID)
{
Project p = new Project();
p = null;
SqlCommand cmdGetProject = new SqlCommand("PC_Return_Project", conn);
cmdGetProject.CommandType = CommandType.StoredProcedure;
cmdGetProject.Parameters.Add("@pID", pID);
conn.Open();
drProject = cmdGetProject.ExecuteReader();
if (drProject.Read())
{
p = new Project();
p.ProjName = drProject["projName"].ToString();
p.ProjDescrip = drProject["description"].ToString();
p.ProjRequestedDeadline = drProject["requestedDeadline"].ToString();
p.ProjBasecampURL = drProject["basecampURL"].ToString();
p.ProjStatus = drProject["Status"].ToString();
p.ProjStatusID = Int32.Parse(drProject["statusID"].ToString());
p.ProjFreq = drProject["freqtype"].ToString();
p.ProjFreqID = Int32.Parse(drProject["freqID"].ToString());
p.ProjPriority = drProject["priority"].ToString();
p.ProjPriorityID = Int32.Parse(drProject["priorityID"].ToString());
p.ProjDateProposed = drProject["dateProposed"].ToString();
drProject.Close();
conn.Close();
}
return p;
} 12 4420
stack overflow almost always happens when infinite recursive method calls
occur. probably, in a property of Project class there is such code :
private string projName;
public string ProjName
{
get
{
return ProjName;
}
set
{
ProjName = value;
}
}
when do you receive the exception (on what line of code)?
--
Vadym Stetsyak aka Vadmyst http://vadmyst.blogspot.com
"Amy" <am*******@mccombs.utexas.edu> wrote in message
news:6c********************************@4ax.com... I'm getting a System.StackOverflowException, and I can't see why. Here's the code that's throwing the exception. I don't see anyting that's recursive about it. Any help is appreciated (including help in debugging - I'm not sure what I'd put in a try or catch clause here):
DataDealings sql = new DataDealings();
myProject = sql.GetProject(pID);
--------------------------------------------------------------------------
----------- public Project GetProject (int pID) { Project p = new Project(); p = null;
SqlCommand cmdGetProject = new SqlCommand("PC_Return_Project", conn); cmdGetProject.CommandType = CommandType.StoredProcedure; cmdGetProject.Parameters.Add("@pID", pID);
conn.Open(); drProject = cmdGetProject.ExecuteReader();
if (drProject.Read()) { p = new Project(); p.ProjName = drProject["projName"].ToString(); p.ProjDescrip = drProject["description"].ToString(); p.ProjRequestedDeadline = drProject["requestedDeadline"].ToString(); p.ProjBasecampURL = drProject["basecampURL"].ToString(); p.ProjStatus = drProject["Status"].ToString(); p.ProjStatusID = Int32.Parse(drProject["statusID"].ToString()); p.ProjFreq = drProject["freqtype"].ToString(); p.ProjFreqID = Int32.Parse(drProject["freqID"].ToString()); p.ProjPriority = drProject["priority"].ToString(); p.ProjPriorityID = Int32.Parse(drProject["priorityID"].ToString()); p.ProjDateProposed = drProject["dateProposed"].ToString();
drProject.Close(); conn.Close(); }
return p; }
Yeah, there is!
Can you explan to me why that's recursive?
TIA,
Amy
On Mon, 17 Oct 2005 19:47:53 +0300, "The Crow" <q> wrote: stack overflow almost always happens when infinite recursive method calls occur. probably, in a property of Project class there is such code :
private string projName;
public string ProjName { get { return ProjName; } set { ProjName = value; } }
I don't know - the error doesn't give me a line number.
On Mon, 17 Oct 2005 19:51:00 +0300, "Vadym Stetsyak" <va*****@ukr.net>
wrote: when do you receive the exception (on what line of code)?
recursive is, when a method calls itself. here is a better code snippet to
explain. function calculates i! :
private void Functionel(int i)
{
while(i > 0)
i = i * Functionel(i - 1);
}
you have to learn "Debugging" (if you dont know).
In it’s simplest form, recursion is just calling the same function or method
over and over again from within that function or method.
In Crow’s example, ProjName and projName are different identifiers within a
block of code, and requesting the value from ProjName attempts to return the
value from ProjName (capital p) rather than from projName (lowercase p). In
doing so, the get portion ProjName of is continually called without end until
you run out of space on the stack.
Brendan
"Amy" wrote: Yeah, there is! Can you explan to me why that's recursive?
TIA,
Amy
On Mon, 17 Oct 2005 19:47:53 +0300, "The Crow" <q> wrote:
stack overflow almost always happens when infinite recursive method calls occur. probably, in a property of Project class there is such code :
private string projName;
public string ProjName { get { return ProjName; } set { ProjName = value; } }
"Amy" <am*******@mccombs.utexas.edu> wrote in message
news:7r********************************@4ax.com... Yeah, there is! Can you explan to me why that's recursive?
OK,
remember that properties are really nothing more than methods that use different syntax.
Case 1 (Recursive); never reference x
private string x;
public string X {get {return (X);} set {X = value;} // this is recursive
----------------------
Case 2 (Nonrecursive); we do reference x
private string x;
public string X {get {return (x);} set {x = value;} // this is NOT recursive
----------------------
It is easier to see the recursion in case 1 if we change the property name.
Case 1 Mark II (Recursive) never reference x
private string x;
public string Qwerty {get {return (Qwerty);} set {Qwerty = value;} // this is recursive
Nowhere do you reference the member x.
Any call to Qwerty will keep calling Qwerty forever.
Hope this helps
Bill
Amy <am*******@mccombs.utexas.edu> wrote: I'm getting a System.StackOverflowException, and I can't see why. Here's the code that's throwing the exception. I don't see anyting that's recursive about it. Any help is appreciated (including help in debugging - I'm not sure what I'd put in a try or catch clause here):
Could you post a short but complete program which demonstrates the
problem?
See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
One thing which is odd though:
Project p = new Project();
p = null;
Why bother to create a new object, assign a reference to a variable,
and then set the variable's value to null straight afterwards?
Do you have a stack trace from the exception? That would help a lot.
As for debugging: I suggest you try breaking into the debugger at the
start of GetProject, and then just step through the code...
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Amy <am*******@mccombs.utexas.edu> wrote: Yeah, there is! Can you explan to me why that's recursive?
Well, what do you expect
return ProjName;
to do?
Note that the name of the variable is projName - ProjName is the name
of the *property*.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Unfortunately, I can't run the debugger on my projects (it has to do
with permissions in my development enviroment, which I don't have
control over), and I didn't get a stack trace on this error, either.
My thought regarding setting p to null was in the event that the
stored procedure didn't return a project, the value ought to be null.
Am I missing something conceptually?
I understand the nature of recursion, what I was missing was the case
sensitivity - that is, I know c# is case sensitive, but I'm still not
good at noticing when I've mixed up my cases.
Thanks, everyone, for the help!
--Amy
On Mon, 17 Oct 2005 18:59:05 +0100, Jon Skeet [C# MVP]
<sk***@pobox.com> wrote: Amy <am*******@mccombs.utexas.edu> wrote: I'm getting a System.StackOverflowException, and I can't see why. Here's the code that's throwing the exception. I don't see anyting that's recursive about it. Any help is appreciated (including help in debugging - I'm not sure what I'd put in a try or catch clause here):
Could you post a short but complete program which demonstrates the problem?
See http://www.pobox.com/~skeet/csharp/complete.html for details of what I mean by that.
One thing which is odd though:
Project p = new Project(); p = null;
Why bother to create a new object, assign a reference to a variable, and then set the variable's value to null straight afterwards?
Do you have a stack trace from the exception? That would help a lot.
As for debugging: I suggest you try breaking into the debugger at the start of GetProject, and then just step through the code...
Amy <am*******@mccombs.utexas.edu> wrote: Unfortunately, I can't run the debugger on my projects (it has to do with permissions in my development enviroment, which I don't have control over), and I didn't get a stack trace on this error, either.
If you can't run a debugger, you're being stifled in development.
Personally I don't use a debugger much, but it's definitely worth
kicking up a stink about that.
My thought regarding setting p to null was in the event that the stored procedure didn't return a project, the value ought to be null. Am I missing something conceptually?
It's not the fact that you're setting it to null that's the problem -
it's that you're creating a new project for no reason. Why don't you
just do:
Project p = null;
instead?
I understand the nature of recursion, what I was missing was the case sensitivity - that is, I know c# is case sensitive, but I'm still not good at noticing when I've mixed up my cases.
In that case, I'd suggest using a different naming convention for your
variables, eg m_name instead of name. Personally I prefer name (and
Name for the property) but if it's likely to cause errors like this,
it's worth changing.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Martyn Wynne |
last post by:
Hi,
Can anyone please tell me if there is any reason why when i am streaming
from a webrequest (decompressing on route) to a file on the hard drive, i
would be getting an exception of Filestream...
|
by: Anders Both |
last post by:
In a system with asynkronius socket and different collection, there are some
times throw a System.StackOverflowException .
I cannot really figur out why , Can someone say something clever about...
|
by: Patrick.O.Ige |
last post by:
Error:-
System.StackOverflowException: Exception of type
System.StackOverflowException was thrown.
When is this thrown..
Any ideas
|
by: Simon Harris |
last post by:
Hi All,
When I set the property of title in my class (Shown below) I get a
"Exception of type System.StackOverflowException was thrown." error message.
I'm guessing I got some sort of horrible...
|
by: Nikhil Khade |
last post by:
Hello,
After around 3 months, I reopened a old VB.NET solutions which used to work
(and build) without any errors. Just to test it again, I build it again and
it completed, without any errors,...
|
by: Mae Lim |
last post by:
Dear all,
I'm new to C# WebServices. I compile the WebService project it return no
errors "Build: 1 succeeded, 0 failed, 0 skipped".
Basically I have 2 WebMethod, when I try to invoke the...
|
by: Modica82 |
last post by:
Hi all,
I am trying to generate a stub class for my web service using wsdl.exe but
every time i run it from the visual studio command prompt i get a
System.StackOverFlowException.
Has anyone...
|
by: HyVong |
last post by:
Hi Everyone, please help, i'm very frustrated because i can't run my
application.
I built my application using the .NET Installer, i ran the installer on
the development machine and it sets the...
|
by: daz_oldham |
last post by:
Hi everyone
As my expedition into OOP takes another shaky step, I now am getting
the error:
An unhandled exception of type 'System.StackOverflowException' occurred
in xxx.dll.
In my...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
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 project—planning, coding, testing,...
|
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...
| |