Question About Design

J

Joey

Hello guys,

I am currently working on a fairly complex asp.net project using C#,
VS2005, and several third-party components. I have a question about
how to remedy a problem with it and maybe about how to redesign it...

Okay, so I originally set things up like this...I have about 50
configuration settings in the form of <appSettings> keys in my
Web.config file. I designed it this way to allow for us to be able to
make changes to the app (with Notepad or something), save the changes,
which would also conveniently automatically reload the website and the
changes.

I then wrote a custom class called WebsiteSettings that has matching
properties and a LoadConfiguration() function for populating them with
the data from the Web.config file (all via calls to
ConfigurationManager.AppSettings.Get()). I wrote the class as static
public with all the matching properties as static.

I then created a Global.asax file and called
WebsiteSettings.LoadConfiguration() in the Application_Start() event
handler. The idea here is, since the class and member properties are
all static, it gets populated and used only once during each
Application_Start(). Having loaded the configuration this way I can
then conveniently access all settings in my code in this
manner...'WebsiteSettings.SomeSetting'.

Everything was working great until the other day when I added some new
settings and started receiving the following runtime error each time I
tried to run the app...

"An unhandled exception of type 'System.StackOverflowException'
occurred in App_Code.gilihxiu.dll".

This app is built as a "Web Site" and not as a regular C# project/
solution. Also, in this scenario I am running it in File-system mode,
not IIS.

Now, I would like to know...

1. What do you guys think about this setup?

2. Can you guys tell me what is causing the StackOverflowException...I
suspect maybe I am just trying to stick too much data in my static
class?

3. Can I make the current setup work somehow, or do I need to do a
complete redesign...maybe move to a scenario where my class gets
instantiated each time I want to use a setting, instead of always
having everything as static. I REALLY DO NOT want to do that as it
will require a lot of code changes.

Thanks for all of your answers!
 
B

bruce barker

a stack overflow is caused my too many nested function calls, not too much
data. normally the stack overflow is caused by a recursive call.

-- bruce (sqlwork.com)
 
A

Alex Meleta

Hi Joey,

First, debug your app, at least call stack available under StackOverflowException
exception. Then, take a look at your properties of the WebsiteSettings. Common
mistake caused StackOverflowException is the property called themself and
that follows from your description.

Regards, Alex
[TechBlog] http://devkids.blogspot.com



J> Hello guys,
J>
J> I am currently working on a fairly complex asp.net project using C#,
J> VS2005, and several third-party components. I have a question about
J> how to remedy a problem with it and maybe about how to redesign it...
J>
J> Okay, so I originally set things up like this...I have about 50
J> configuration settings in the form of <appSettings> keys in my
J> Web.config file. I designed it this way to allow for us to be able to
J> make changes to the app (with Notepad or something), save the
J> changes, which would also conveniently automatically reload the
J> website and the changes.
J>
J> I then wrote a custom class called WebsiteSettings that has matching
J> properties and a LoadConfiguration() function for populating them
J> with the data from the Web.config file (all via calls to
J> ConfigurationManager.AppSettings.Get()). I wrote the class as static
J> public with all the matching properties as static.
J>
J> I then created a Global.asax file and called
J> WebsiteSettings.LoadConfiguration() in the Application_Start() event
J> handler. The idea here is, since the class and member properties are
J> all static, it gets populated and used only once during each
J> Application_Start(). Having loaded the configuration this way I can
J> then conveniently access all settings in my code in this
J> manner...'WebsiteSettings.SomeSetting'.
J>
J> Everything was working great until the other day when I added some
J> new settings and started receiving the following runtime error each
J> time I tried to run the app...
J>
J> "An unhandled exception of type 'System.StackOverflowException'
J> occurred in App_Code.gilihxiu.dll".
J>
J> This app is built as a "Web Site" and not as a regular C# project/
J> solution. Also, in this scenario I am running it in File-system mode,
J> not IIS.
J>
J> Now, I would like to know...
J>
J> 1. What do you guys think about this setup?
J>
J> 2. Can you guys tell me what is causing the
J> StackOverflowException...I suspect maybe I am just trying to stick
J> too much data in my static class?
J>
J> 3. Can I make the current setup work somehow, or do I need to do a
J> complete redesign...maybe move to a scenario where my class gets
J> instantiated each time I want to use a setting, instead of always
J> having everything as static. I REALLY DO NOT want to do that as it
J> will require a lot of code changes.
J>
J> Thanks for all of your answers!
J>
 
J

Joey

Hi Joey,

First, debug your app, at least call stack available under StackOverflowException
exception. Then, take a look at your properties of the WebsiteSettings. Common
mistake caused StackOverflowException is the property called themself and
that follows from your description.

Regards, Alex
[TechBlog]http://devkids.blogspot.com

J> Hello guys,
J>
J> I am currently working on a fairly complex asp.net project using C#,
J> VS2005, and several third-party components. I have a question about
J> how to remedy a problem with it and maybe about how to redesign it...
J>
J> Okay, so I originally set things up like this...I have about 50
J> configuration settings in the form of <appSettings> keys in my
J> Web.config file. I designed it this way to allow for us to be able to
J> make changes to the app (with Notepad or something), save the
J> changes, which would also conveniently automatically reload the
J> website and the changes.
J>
J> I then wrote a custom class called WebsiteSettings that has matching
J> properties and a LoadConfiguration() function for populating them
J> with the data from the Web.config file (all via calls to
J> ConfigurationManager.AppSettings.Get()). I wrote the class as static
J> public with all the matching properties as static.
J>
J> I then created a Global.asax file and called
J> WebsiteSettings.LoadConfiguration() in the Application_Start() event
J> handler. The idea here is, since the class and member properties are
J> all static, it gets populated and used only once during each
J> Application_Start(). Having loaded the configuration this way I can
J> then conveniently access all settings in my code in this
J> manner...'WebsiteSettings.SomeSetting'.
J>
J> Everything was working great until the other day when I added some
J> new settings and started receiving the following runtime error each
J> time I tried to run the app...
J>
J> "An unhandled exception of type 'System.StackOverflowException'
J> occurred in App_Code.gilihxiu.dll".
J>
J> This app is built as a "Web Site" and not as a regular C# project/
J> solution. Also, in this scenario I am running it in File-system mode,
J> not IIS.
J>
J> Now, I would like to know...
J>
J> 1. What do you guys think about this setup?
J>
J> 2. Can you guys tell me what is causing the
J> StackOverflowException...I suspect maybe I am just trying to stick
J> too much data in my static class?
J>
J> 3. Can I make the current setup work somehow, or do I need to do a
J> complete redesign...maybe move to a scenario where my class gets
J> instantiated each time I want to use a setting, instead of always
J> having everything as static. I REALLY DO NOT want to do that as it
J> will require a lot of code changes.
J>
J> Thanks for all of your answers!
J>

Okay thanks. I found the problem. In one of my properties I was
returning the public value instead of the private one. This was
effectively and infinite loop, and that caused the
StackOverflowException.

Do you guys see any problems with storing my configuration in such a
large static class like this?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top