Solved

Public Class creates System.StackOverflowException

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

718 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