473,407 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

StackOverflowException with attribute

Hi,
I have a project based on .Net 1.1 and VS 2003,now I am trying to upgrade it
to .Net 2.0 and VS 2005.The project passes the 'Build Solution',but When I
start Debug, it suddenly comes StackOverflowException and Debug stops.

The main Exception point is the function below:

public System.ComponentModel.PropertyDescriptorCollection
GetStatefulPropertyDescriptors()
{
DataObject.StatefulPropertyAttribute a = new
StatefulPropertyAttribute();
return this.GetProperties(new Attribute[] { a }); //exception point
//class System.Attribute that is base class for customer attributes
}

[AttributeUsage(AttributeTargets.Property, AllowMultiple=false,
Inherited=true)]
public class StatefulPropertyAttribute : Attribute{}

Under .Net 1.1 and VS 2003 there is no problem, no exception for the
function, but why does it come StackOverflowException under .Net 2.0 and How
to solve it?

--
windsim
May 11 '07 #1
9 2473
Well, how is this.GetProperties(...) implemented? Is this an
ICustomTypeDescriptor implementation? If so, what are you calling? It
should normally be something like
TypeDescriptor.GetProperties(GetType()) or (GetType(), attributes)...

Marc

May 11 '07 #2
windsim,

Well, more likely than not you have a recursive call somewhere (or
something that results in an endless loop of calls). Have you set a
breakpoint and looked a the call stack to see where the calls are repeating
in a loop?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"windsim" <wi*****@discussions.microsoft.comwrote in message
news:AB**********************************@microsof t.com...
Hi,
I have a project based on .Net 1.1 and VS 2003,now I am trying to upgrade
it
to .Net 2.0 and VS 2005.The project passes the 'Build Solution',but When I
start Debug, it suddenly comes StackOverflowException and Debug stops.

The main Exception point is the function below:

public System.ComponentModel.PropertyDescriptorCollection
GetStatefulPropertyDescriptors()
{
DataObject.StatefulPropertyAttribute a = new
StatefulPropertyAttribute();
return this.GetProperties(new Attribute[] { a }); //exception point
//class System.Attribute that is base class for customer attributes
}

[AttributeUsage(AttributeTargets.Property, AllowMultiple=false,
Inherited=true)]
public class StatefulPropertyAttribute : Attribute{}

Under .Net 1.1 and VS 2003 there is no problem, no exception for the
function, but why does it come StackOverflowException under .Net 2.0 and
How
to solve it?

--
windsim

May 11 '07 #3
this.GetProperties(...) is a member function of class
PropertyDescriptorCollection:
public PropertyDescriptorCollection GetProperties(Attribute[] attributes){...}

where

class PropertyDescriptorCollection : IList, IDictionary, ICollection,
IEnumerable
--
windsim
"Marc Gravell" wrote:
Well, how is this.GetProperties(...) implemented? Is this an
ICustomTypeDescriptor implementation? If so, what are you calling? It
should normally be something like
TypeDescriptor.GetProperties(GetType()) or (GetType(), attributes)...

Marc

May 11 '07 #4
On May 11, 3:04 pm, windsim <wind...@discussions.microsoft.comwrote:
this.GetProperties(...) is a member function of class
PropertyDescriptorCollection:
public PropertyDescriptorCollection GetProperties(Attribute[] attributes){...}

where

class PropertyDescriptorCollection : IList, IDictionary, ICollection,
IEnumerable
--
windsim

"Marc Gravell" wrote:
Well, how is this.GetProperties(...) implemented? Is this an
ICustomTypeDescriptor implementation? If so, what are you calling? It
should normally be something like
TypeDescriptor.GetProperties(GetType()) or (GetType(), attributes)...
Marc
The overflow exception is caused by the recursion depth that exceeds a
threshold value. If I understand this code correctly you should try
increasing this max recursion depth to solve the problem.

Cheers,
Stefan.

May 11 '07 #5
Thanks guys!

public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{
PropertyDescriptorCollection globalizedProps;
PropertyDescriptorCollection baseProps =
TypeDescriptor.GetProperties(this, attributes, true);
....
}
I can not set break point at above code line and I think the problem is
maybe TypeDescriptor.GetProperties(...)

The info from call stack looks like a endless loop below :
....
[External Code]

SystemFrameworks.dll!SystemFrameworks.DataObject.G lobalizedObject.GetProperties(System.Attribute[] attributes = {Dimensions:[1]}) Line 350 + 0xd bytes C#

SystemFrameworks.dll!SystemFrameworks.DataObject.M oduleProperties.GetStatefulPropertyDescriptors() Line 92 + 0x26 bytes C#

SystemFrameworks.dll!SystemFrameworks.DataObject.M oduleProperties.GetModulePropertyListCurrent(Syste mFrameworks.DataObject.ModuleProperties
mp = {SystemFrameworks.DataObject.DTMProperties}) Line 122 + 0x8 bytes C#

SystemFrameworks.dll!SystemFrameworks.DataObject.M oduleProperties.ToString()
Line 350 + 0xb bytes C#

SystemFrameworks.dll!SystemFrameworks.DataObject.M oduleProperties.GetHashCode() Line 313 + 0x7 bytes C#
[External Code]

by the way how to increase this max recursion depth in VS 2005?
--
windsim
"Nicholas Paldino [.NET/C# MVP]" wrote:
windsim,

Well, more likely than not you have a recursive call somewhere (or
something that results in an endless loop of calls). Have you set a
breakpoint and looked a the call stack to see where the calls are repeating
in a loop?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"windsim" <wi*****@discussions.microsoft.comwrote in message
news:AB**********************************@microsof t.com...
Hi,
I have a project based on .Net 1.1 and VS 2003,now I am trying to upgrade
it
to .Net 2.0 and VS 2005.The project passes the 'Build Solution',but When I
start Debug, it suddenly comes StackOverflowException and Debug stops.

The main Exception point is the function below:

public System.ComponentModel.PropertyDescriptorCollection
GetStatefulPropertyDescriptors()
{
DataObject.StatefulPropertyAttribute a = new
StatefulPropertyAttribute();
return this.GetProperties(new Attribute[] { a }); //exception point
//class System.Attribute that is base class for customer attributes
}

[AttributeUsage(AttributeTargets.Property, AllowMultiple=false,
Inherited=true)]
public class StatefulPropertyAttribute : Attribute{}

Under .Net 1.1 and VS 2003 there is no problem, no exception for the
function, but why does it come StackOverflowException under .Net 2.0 and
How
to solve it?

--
windsim


May 11 '07 #6
I don't know what atlaste was trying to indicate by saying to raise the
maximum recursion depth, because in the end, if you have a loop that loops
infinitely, it's always going to be larger than whatever the threshold is.

To me, it would seem that the call to GetProperties on the
TypeDescriptor class is calling back into your GetProperities method, and
it's always going to instantiate another call.

You need to find some way to break this loop. What is it that you are
trying to do?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"windsim" <wi*****@discussions.microsoft.comwrote in message
news:2C**********************************@microsof t.com...
Thanks guys!

public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{
PropertyDescriptorCollection globalizedProps;
PropertyDescriptorCollection baseProps =
TypeDescriptor.GetProperties(this, attributes, true);
...
}
I can not set break point at above code line and I think the problem is
maybe TypeDescriptor.GetProperties(...)

The info from call stack looks like a endless loop below :
...
[External Code]

SystemFrameworks.dll!SystemFrameworks.DataObject.G lobalizedObject.GetProperties(System.Attribute[]
attributes = {Dimensions:[1]}) Line 350 + 0xd bytes C#

SystemFrameworks.dll!SystemFrameworks.DataObject.M oduleProperties.GetStatefulPropertyDescriptors()
Line 92 + 0x26 bytes C#

SystemFrameworks.dll!SystemFrameworks.DataObject.M oduleProperties.GetModulePropertyListCurrent(Syste mFrameworks.DataObject.ModuleProperties
mp = {SystemFrameworks.DataObject.DTMProperties}) Line 122 + 0x8 bytes C#

SystemFrameworks.dll!SystemFrameworks.DataObject.M oduleProperties.ToString()
Line 350 + 0xb bytes C#

SystemFrameworks.dll!SystemFrameworks.DataObject.M oduleProperties.GetHashCode()
Line 313 + 0x7 bytes C#
[External Code]

by the way how to increase this max recursion depth in VS 2005?
--
windsim
"Nicholas Paldino [.NET/C# MVP]" wrote:
>windsim,

Well, more likely than not you have a recursive call somewhere (or
something that results in an endless loop of calls). Have you set a
breakpoint and looked a the call stack to see where the calls are
repeating
in a loop?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"windsim" <wi*****@discussions.microsoft.comwrote in message
news:AB**********************************@microso ft.com...
Hi,
I have a project based on .Net 1.1 and VS 2003,now I am trying to
upgrade
it
to .Net 2.0 and VS 2005.The project passes the 'Build Solution',but
When I
start Debug, it suddenly comes StackOverflowException and Debug stops.

The main Exception point is the function below:

public System.ComponentModel.PropertyDescriptorCollection
GetStatefulPropertyDescriptors()
{
DataObject.StatefulPropertyAttribute a = new
StatefulPropertyAttribute();
return this.GetProperties(new Attribute[] { a }); //exception
point
//class System.Attribute that is base class for customer
attributes
}

[AttributeUsage(AttributeTargets.Property, AllowMultiple=false,
Inherited=true)]
public class StatefulPropertyAttribute : Attribute{}

Under .Net 1.1 and VS 2003 there is no problem, no exception for the
function, but why does it come StackOverflowException under .Net 2.0
and
How
to solve it?

--
windsim



May 11 '07 #7
One more thing: This is an implementation of the ICustomTypeDescriptor
interface, class name is GlobalizedObject.

Thia whole loop starts when some external code calls the GetHashCode() of my
object of type DTMProperties (inherits from ModuleProperties, inherits from
GlobalizedObject). The stack trace shows below shows that my
ModuleProperties.GetHashCode() method calls ModuleProperties.ToString().

The ToString method calls the GlobalizedObject.GetProperties(...) method in
order to return the name/value pairs of all properties that have a special
attribute.

The code that now executes does the following:

public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{
PropertyDescriptorCollection globalizedProps;
PropertyDescriptorCollection baseProps =
TypeDescriptor.GetProperties(this, attributes, true);
....
}

The next thing happening according to the stack trace, is that we call into
some external code (probably the TypeDescriptor.GetProperties(...)), and then
we get back into the GetHashCode. Thus an infinite loop.

So the question is whether the .NET 2.0 implementation of
TypeDescriptor.GetProperties(...) calls the GetHashCode method for some
reason now? And was that not the case in 1.1?

Here is a more readable version of my stack trace:
..... (it just repeats itself from here)
[External Code]
SystemFrameworks.DataObject.GlobalizedObject.GetPr operties(System.Attribute[] attributes = {Dimensions:[1]})
SystemFrameworks.DataObject.ModuleProperties.GetSt atefulPropertyDescriptors()
SystemFrameworks.DataObject.ModuleProperties.GetMo dulePropertyListCurrent(SystemFrameworks.DataObjec t.ModuleProperties
mp = {SystemFrameworks.DataObject.DTMProperties})
SystemFrameworks.DataObject.ModuleProperties.ToStr ing()
SystemFrameworks.DataObject.ModuleProperties.GetHa shCode()
[External Code]

SystemFrameworks.DataObject.GlobalizedObject.GetPr operties(System.Attribute[]
attributes = {Dimensions:[1]})
SystemFrameworks.DataObject.ModuleProperties.GetSt atefulPropertyDescriptors()
SystemFrameworks.DataObject.ModuleProperties.GetMo dulePropertyListCurrent(SystemFrameworks.DataObjec t.ModuleProperties
mp = {SystemFrameworks.DataObject.DTMProperties})
SystemFrameworks.DataObject.ModuleProperties.ToStr ing()
SystemFrameworks.DataObject.ModuleProperties.GetHa shCode()
[External Code]

--
windsim
"windsim" wrote:
Thanks guys!

public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{
PropertyDescriptorCollection globalizedProps;
PropertyDescriptorCollection baseProps =
TypeDescriptor.GetProperties(this, attributes, true);
...
}
I can not set break point at above code line and I think the problem is
maybe TypeDescriptor.GetProperties(...)

The info from call stack looks like a endless loop below :
...
[External Code]

SystemFrameworks.dll!SystemFrameworks.DataObject.G lobalizedObject.GetProperties(System.Attribute[] attributes = {Dimensions:[1]}) Line 350 + 0xd bytes C#

SystemFrameworks.dll!SystemFrameworks.DataObject.M oduleProperties.GetStatefulPropertyDescriptors() Line 92 + 0x26 bytes C#

SystemFrameworks.dll!SystemFrameworks.DataObject.M oduleProperties.GetModulePropertyListCurrent(Syste mFrameworks.DataObject.ModuleProperties
mp = {SystemFrameworks.DataObject.DTMProperties}) Line 122 + 0x8 bytes C#

SystemFrameworks.dll!SystemFrameworks.DataObject.M oduleProperties.ToString()
Line 350 + 0xb bytes C#

SystemFrameworks.dll!SystemFrameworks.DataObject.M oduleProperties.GetHashCode() Line 313 + 0x7 bytes C#
[External Code]

by the way how to increase this max recursion depth in VS 2005?
--
windsim
"Nicholas Paldino [.NET/C# MVP]" wrote:
windsim,

Well, more likely than not you have a recursive call somewhere (or
something that results in an endless loop of calls). Have you set a
breakpoint and looked a the call stack to see where the calls are repeating
in a loop?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"windsim" <wi*****@discussions.microsoft.comwrote in message
news:AB**********************************@microsof t.com...
Hi,
I have a project based on .Net 1.1 and VS 2003,now I am trying to upgrade
it
to .Net 2.0 and VS 2005.The project passes the 'Build Solution',but When I
start Debug, it suddenly comes StackOverflowException and Debug stops.
>
The main Exception point is the function below:
>
public System.ComponentModel.PropertyDescriptorCollection
GetStatefulPropertyDescriptors()
{
DataObject.StatefulPropertyAttribute a = new
StatefulPropertyAttribute();
return this.GetProperties(new Attribute[] { a }); //exception point
//class System.Attribute that is base class for customer attributes
}
>
[AttributeUsage(AttributeTargets.Property, AllowMultiple=false,
Inherited=true)]
public class StatefulPropertyAttribute : Attribute{}
>
Under .Net 1.1 and VS 2003 there is no problem, no exception for the
function, but why does it come StackOverflowException under .Net 2.0 and
How
to solve it?
>
--
windsim
May 11 '07 #8
I figured that the recursion wasn't infinite (but just deep). Since
semantics of methods (like GetProperties) change that could explain
the behaviour (it worked in 1.1 but not in 2.0). Changing the max
recursion depth not only helps to identify the problem in that
particular case but also helps to solve the special case problem. I
used to have these kind of problems all the time...

However, it seems like it's the GetHashCode that makes the thing
infinite so you were right after all.

I can think of a dozen reasons why they opted for using GetHashCode in
2.0 and not in 1.1. After all, the features of the language evolved. I
would make a new implementation of getHashcode and equals.

Cheers,
Stefan.
On May 11, 4:00 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
I don't know what atlaste was trying to indicate by saying to raise the
maximum recursion depth, because in the end, if you have a loop that loops
infinitely, it's always going to be larger than whatever the threshold is.

To me, it would seem that the call to GetProperties on the
TypeDescriptor class is calling back into your GetProperities method, and
it's always going to instantiate another call.

You need to find some way to break this loop. What is it that you are
trying to do?

--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com

"windsim" <wind...@discussions.microsoft.comwrote in message

news:2C**********************************@microsof t.com...
Thanks guys!
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{
PropertyDescriptorCollection globalizedProps;
PropertyDescriptorCollection baseProps =
TypeDescriptor.GetProperties(this, attributes, true);
...
}
I can not set break point at above code line and I think the problem is
maybe TypeDescriptor.GetProperties(...)
The info from call stack looks like a endless loop below :
...
[External Code]
SystemFrameworks.dll!SystemFrameworks.DataObject.G lobalizedObject.GetProperties(System.Attribute[]
attributes = {Dimensions:[1]}) Line 350 + 0xd bytes C#
SystemFrameworks.dll!SystemFrameworks.DataObject.M oduleProperties.GetStatefulPropertyDescriptors()
Line 92 + 0x26 bytes C#
SystemFrameworks.dll!SystemFrameworks.DataObject.M oduleProperties.GetModulePropertyListCurrent(Syste mFrameworks.DataObject.ModuleProperties
mp = {SystemFrameworks.DataObject.DTMProperties}) Line 122 + 0x8 bytes C#
SystemFrameworks.dll!SystemFrameworks.DataObject.M oduleProperties.ToString()
Line 350 + 0xb bytes C#
SystemFrameworks.dll!SystemFrameworks.DataObject.M oduleProperties.GetHashCode()
Line 313 + 0x7 bytes C#
[External Code]
by the way how to increase this max recursion depth in VS 2005?
--
windsim
"Nicholas Paldino [.NET/C# MVP]" wrote:
windsim,
Well, more likely than not you have a recursive call somewhere (or
something that results in an endless loop of calls). Have you set a
breakpoint and looked a the call stack to see where the calls are
repeating
in a loop?
--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com
"windsim" <wind...@discussions.microsoft.comwrote in message
news:AB**********************************@microso ft.com...
Hi,
I have a project based on .Net 1.1 and VS 2003,now I am trying to
upgrade
it
to .Net 2.0 and VS 2005.The project passes the 'Build Solution',but
When I
start Debug, it suddenly comes StackOverflowException and Debug stops.
The main Exception point is the function below:
public System.ComponentModel.PropertyDescriptorCollection
GetStatefulPropertyDescriptors()
{
DataObject.StatefulPropertyAttribute a = new
StatefulPropertyAttribute();
return this.GetProperties(new Attribute[] { a }); //exception
point
//class System.Attribute that is base class for customer
attributes
}
[AttributeUsage(AttributeTargets.Property, AllowMultiple=false,
Inherited=true)]
public class StatefulPropertyAttribute : Attribute{}
Under .Net 1.1 and VS 2003 there is no problem, no exception for the
function, but why does it come StackOverflowException under .Net 2.0
and
How
to solve it?
--
windsim

May 11 '07 #9
MGWell, how is this.GetProperties(...) implemented? Is this an
MGICustomTypeDescriptor implementation?
---
wthis.GetProperties(...) is a member function of class
wPropertyDescriptorCollection:
wpublic PropertyDescriptorCollection GetProperties(Attribute[]
attributes){...}
---
wThis is an implementation of the ICustomTypeDescriptor
winterface, class name is GlobalizedObject.
---
Why didn't you say that the first time? Anyways... in the general
case, I would *definitely* be treating this as a huge warning sign;
you shouldn't be coming anywhere *near* blowing the stack just to read
metadata. For reference, I still think there is a loop in here: your
ICustomTypeDescriptor implementation uses the *instance* form of
TypeDescriptor.GetProperties... and the first thing that does is ask
"does this instance implement ICustomTypeDescriptor? If so, call that
instead..." - which is why I posted about using the *Type* form of
TypeDescriptor.GetProperties.

Actually, to avoid this hell, I quite like tke 2.0 approach of
TypeDescriptionProvider; this allows you to delegate metadata
provision to a separate class (helping keep each class targetted to
doing one job) - but more importantly it makes the distinction between
the *instance* and *Type* forms disappear; your CustomTypeDescriptor
subclass can of course choose whether to care about instances or not.

Marc

May 11 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jesee | last post by:
I am reading Jeffrey Richter's book "Applied Microsoft .NET Framework programming",i came across "Exception handing". Page 405 says "If the stack overflow occurs within the CLR itself,your...
2
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...
0
by: Elizabeth | last post by:
I have C# dll which I compile using ComInterop True and generate tlb type library. When I call function from the C# dll using below code I get an error "StackOverflowException in mscorlib.dll" ...
3
by: Vladimir Arkhipov | last post by:
Hi, I noticed that finally block is not executed once I got StackOverflowException. Is that a known feature or a bug?
11
by: Alx Sharp | last post by:
Hello group... I've created a collection class that implements the following interfaces: IBindingList, IList, ICollection, IEnumerable and ITypedList: abstract class DataCollectionBase :...
20
by: zapov | last post by:
Hi! I'm having some wierd problems with this exception (error). If I use sql commands to insert data into sql server i get strange behaviour from my application. First I used a single...
8
by: Lars-Erik Aabech | last post by:
Hi! I've got an asp.net page that works for all users except one and that one user only gets the error with a certain parameter set to a certain value. (Same value as the others, but for this...
10
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...
2
by: etienne.maitre | last post by:
Hi, I work against .NET 2.0 using C# 2.0. I am facing a problem trying to serialize the class foo (given below). Basically, foo can contain other foos in a list. When I try to create a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
marktang
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,...
0
Oralloy
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.