[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Public Class creates System.StackOverflowException

Posted on 2004-03-26
4
Medium Priority
?
680 Views
Last Modified: 2013-11-23
I've created a public class with some shared properties that I'll set-up initially in my solution and then use the values in different parts of the solution.

It's possible, if the app.config file isn't set correctly that a blank value could propogate to the shared value.  To prevent this, I've gone for a 'belt & braces' approach where the property has a default value, but also check the value that's sent to make sure it's not blank.

A subset of the  class below;

  Public Class dbInfo
    Private Const dbPathDef As String = "C:\Program Files\Database"

    <System.ComponentModel.Description("The directory path to the database."), _
      System.ComponentModel.DefaultValue(dbPathDef)> _
    Public Shared Property dbPath() As String
      Get
        Return dbPath
      End Get
      Set(ByVal Value As String)
        If Len(Value) = 0 Then
          dbPath = dbPathDef
        Else
          dbPath = Value
        End If
      End Set
    End Property

Although the code compiles ok, it throws the following exception at the 'If Len(Value) = 0 Then' point

An unhandled exception of type 'System.StackOverflowException' occurred in microsoft.visualbasic.dll

I've tried other string comparison methods (Value = "", Value Is Nothing, Value <> "") but still get the same exception thrown

The exception is still produced if I remove the attribute settings.
0
Comment
Question by:MarkNethercott
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 48

Expert Comment

by:Mikal613
ID: 10688194
Represents the error that occurs when the execution stack overflows due to too many method calls.

Description
[Note: StackOverflowException is thrown for execution stack overflow errors, typically in the case of a very deep or unbounded recursion.
The localloc IL instruction throws StackOverflowException.

I guess its too complicated ??????
0
 

Author Comment

by:MarkNethercott
ID: 10694857
Fixed it.  Bit daft really, the System.StackOverflowException was being thrown because of deep recursion, which (I think) was caused because I was setting a value directly to a shared property and for some reason caused the code to go round in a circle - setting the value must set up a call to the property (I guess).

I fixed the problem by defining a Private Shared variable and when the property is called for a set or get then the private shared variable gets changed by the public shared property - actually sensible when you think about it.  A good reference article is;

Microsoft Knowledge Base Article - 308371
HOW TO: Create and Use Shared Members by Using Visual Basic .NET
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q308371&ID=kb;en-us;Q308371&SD=MSDN

0
 

Accepted Solution

by:
ee_ai_construct earned 0 total points
ID: 10724593
Closed, 500 points refunded.
ee_ai_construct
Community Support Moderator
(re-order part number xm34)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question