Monday, March 26, 2012

Serializable ?

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,
JohnIts 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
"WJ" wrote:

> 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 w
eb
> request. Information regarding the origin and location of the exception ca
n
> be
> identified using the exception stack trace below.
> Stack Trace:
> [StackOverflowException: Exception of type System.StackOverflowException w
as
> thrown.]
> ----
--
> Version Information: Microsoft .NET Framework
> Version:1.1.4322.2032; ASP.NET Version:1.1.4322.2032
> Thanks for your help,
> John
>
>
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" <JohnWebbs@.HotMail.Com> wrote in message
news:eSv8lR6tEHA.1008@.tk2msftngp13.phx.gbl...
> 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
>
>
"Kevin Spencer" <kspencer@.takempis.com> wrote in message
news:OI1vAX6tEHA.2800@.tk2msftngp13.phx.gbl...
> 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
"Joel Cade" <joel@.nospam.figtreesolutions.com> wrote in message
news:BCE71E1A-336C-43EC-BB38-2F463144BAF1@.microsoft.com...
> 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

0 comments:

Post a Comment