Solved

Public Class creates System.StackOverflowException

Posted on 2004-03-26
4
667 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

730 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