Serializable ?

W

WJ

I have this class:

******************************************
using System;

namespace myNameSpace.DBRec
{
[Serializable]
public class myRec
{
private string _Field1;
private string _Field2;

public myRec()
{
}

public myRec
(
string Field1
,string Field2
)
{
this._Field1=Field1;
this._Field2=Field2;
}

public string Field1
{
get
{
return _Field1;
}
set
{
Field1=value;
}
}

public string Field2
{
get
{
return _Field2;
}
set
{
Field2=value;
}
}
}
}
******************************************

In my asp.net page, I have:

private string F1="test1";
private string F2="test2";

1. If I call this:

myRec mr=new myRec(F1,F2); then there is no problem.

2. However, if I do these:

myRec mr=myRec();
mr.Field1=F1;
mr.Field2=F2;

then I got the exception below.


Server Error in '/myDotNet' Application.
--------------------------------------------------------------------------------

Exception of type System.StackOverflowException was thrown.
Description: An unhandled exception occurred during the execution of the
current
web request. Please review the stack trace for more information about the
error
and where it originated in the code.

Exception Details: System.StackOverflowException: Exception of type
System.StackOverflowException was thrown.

Source Error:

An unhandled exception was generated during the execution of the current web
request. Information regarding the origin and location of the exception can
be
identified using the exception stack trace below.

Stack Trace:

[StackOverflowException: Exception of type System.StackOverflowException was
thrown.]

--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework
Version:1.1.4322.2032; ASP.NET Version:1.1.4322.2032

Thanks for your help,

John
 
G

Guest

Its because your Field1.Set is circular. Instead of setting the interval
variable _Field1, it ends up calling itself, the Field1.Set by attempting to
do this.Field1 = value;. The Field2.Set has the same problem.

Hope this helps!

Joel Cade, MCSD
Fig Tree Solutions, LLC
http://www.figtreesolutions.com
 
K

Kevin Spencer

Is the following a typo?

myRec mr=myRec();

It's missing the new operator.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

WJ said:
I have this class:

******************************************
using System;

namespace myNameSpace.DBRec
{
[Serializable]
public class myRec
{
private string _Field1;
private string _Field2;

public myRec()
{
}

public myRec
(
string Field1
,string Field2
)
{
this._Field1=Field1;
this._Field2=Field2;
}

public string Field1
{
get
{
return _Field1;
}
set
{
Field1=value;
}
}

public string Field2
{
get
{
return _Field2;
}
set
{
Field2=value;
}
}
}
}
******************************************

In my asp.net page, I have:

private string F1="test1";
private string F2="test2";

1. If I call this:

myRec mr=new myRec(F1,F2); then there is no problem.

2. However, if I do these:

myRec mr=myRec();
mr.Field1=F1;
mr.Field2=F2;

then I got the exception below.


Server Error in '/myDotNet' Application.
-------------------------------------------------------------------------- ------

Exception of type System.StackOverflowException was thrown.
Description: An unhandled exception occurred during the execution of the
current
web request. Please review the stack trace for more information about the
error
and where it originated in the code.

Exception Details: System.StackOverflowException: Exception of type
System.StackOverflowException was thrown.

Source Error:

An unhandled exception was generated during the execution of the current web
request. Information regarding the origin and location of the exception can
be
identified using the exception stack trace below.

Stack Trace:

[StackOverflowException: Exception of type System.StackOverflowException was
thrown.]

--------------------------------------------------------------------------
------
Version Information: Microsoft .NET Framework
Version:1.1.4322.2032; ASP.NET Version:1.1.4322.2032

Thanks for your help,

John
 
W

WJ

Kevin Spencer said:
Is the following a typo?

myRec mr=myRec();

It's missing the new operator.
Yes it did. It is to be "new" always otherwise it would not pass the
compiler.

John
 
W

WJ

Joel Cade said:
Its because your Field1.Set is circular. Instead of setting the interval
variable _Field1, it ends up calling itself, the Field1.Set by attempting
to
do this.Field1 = value;. The Field2.Set has the same problem.
Thanks

John
 

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

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top