473,378 Members | 1,409 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,378 software developers and data experts.

Serailizing Static Variables Problems

I'm trying to serialize a class using the binary formatter without serializing the
'static pastFirstCall as Boolean' variable. Normally private (module-scope)
variables are serialized unless the <NonSerialized> attribute is used.

Public Function NextMessageNo() As Integer
<NonSerialized()> Static pastFirstCall As Boolean = False 'This is
being Serialized!!!!!!!!!!
If Not pastFirstCall Then
mNextMessageNumber = mNextPersistableMessageNo
pastFirstCall = True
End If
NextMessageNo = mNextMessageNumber + 1
mNextMessageNumber = NextMessageNo
End Function
<NonSerialized()> Private mNextMessageNumber As Integer
Using Reflector, I can see that, internally, pastFirstCall is declared as a private
variable as:
Private $STATIC$NextMessageNo$2008$pastFirstCall As BooleanThe problem is that the
<NonSerialized> attribute is not carried forward to this declaration. Are there any
workarounds other than changing the delcaration to private. Has anyone written a
custom attribute to fix it? I have a ton of static's (which I like because they
limit the scope, thus reducing the complexity) and don't want to go thru all my code
changing them to private module-scope declarations. Almost forgot, I'm using the
..NET Framework 1.0 with the latest service packs. Any Ideas?

Thanks - JackRazz

Nov 16 '05 #1
2 1419
Jack,

There really isn't a way to get around this, you will have to move this
to the module level as there is no way to declare the attribute properly on
the variable when it is static in a method call.

Hope this helps.

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

"JackRazz" <Ja******@NotValid.com> wrote in message
news:e8**************@TK2MSFTNGP10.phx.gbl...
I'm trying to serialize a class using the binary formatter without
serializing the
'static pastFirstCall as Boolean' variable. Normally private
(module-scope)
variables are serialized unless the <NonSerialized> attribute is used.

Public Function NextMessageNo() As Integer
<NonSerialized()> Static pastFirstCall As Boolean = False
'This is
being Serialized!!!!!!!!!!
If Not pastFirstCall Then
mNextMessageNumber = mNextPersistableMessageNo
pastFirstCall = True
End If
NextMessageNo = mNextMessageNumber + 1
mNextMessageNumber = NextMessageNo
End Function
<NonSerialized()> Private mNextMessageNumber As Integer
Using Reflector, I can see that, internally, pastFirstCall is declared as
a private
variable as:
Private $STATIC$NextMessageNo$2008$pastFirstCall As BooleanThe problem is
that the
<NonSerialized> attribute is not carried forward to this declaration. Are
there any
workarounds other than changing the delcaration to private. Has anyone
written a
custom attribute to fix it? I have a ton of static's (which I like
because they
limit the scope, thus reducing the complexity) and don't want to go thru
all my code
changing them to private module-scope declarations. Almost forgot, I'm
using the
.NET Framework 1.0 with the latest service packs. Any Ideas?

Thanks - JackRazz

Nov 16 '05 #2
Nicholas,
Thanks for the info. Did they ever fix it with the 1.1 framework?


"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
| Jack,
|
| There really isn't a way to get around this, you will have to move this
| to the module level as there is no way to declare the attribute properly on
| the variable when it is static in a method call.
|
| Hope this helps.
|
| --
| - Nicholas Paldino [.NET/C# MVP]
| - mv*@spam.guard.caspershouse.com
|
| "JackRazz" <Ja******@NotValid.com> wrote in message
| news:e8**************@TK2MSFTNGP10.phx.gbl...
| > I'm trying to serialize a class using the binary formatter without
| > serializing the
| > 'static pastFirstCall as Boolean' variable. Normally private
| > (module-scope)
| > variables are serialized unless the <NonSerialized> attribute is used.
| >
| > Public Function NextMessageNo() As Integer
| > <NonSerialized()> Static pastFirstCall As Boolean = False
| > 'This is
| > being Serialized!!!!!!!!!!
| > If Not pastFirstCall Then
| > mNextMessageNumber = mNextPersistableMessageNo
| > pastFirstCall = True
| > End If
| > NextMessageNo = mNextMessageNumber + 1
| > mNextMessageNumber = NextMessageNo
| > End Function
| > <NonSerialized()> Private mNextMessageNumber As Integer
| >
| >
| > Using Reflector, I can see that, internally, pastFirstCall is declared as
| > a private
| > variable as:
| > Private $STATIC$NextMessageNo$2008$pastFirstCall As BooleanThe problem is
| > that the
| > <NonSerialized> attribute is not carried forward to this declaration. Are
| > there any
| > workarounds other than changing the delcaration to private. Has anyone
| > written a
| > custom attribute to fix it? I have a ton of static's (which I like
| > because they
| > limit the scope, thus reducing the complexity) and don't want to go thru
| > all my code
| > changing them to private module-scope declarations. Almost forgot, I'm
| > using the
| > .NET Framework 1.0 with the latest service packs. Any Ideas?
| >
| > Thanks - JackRazz
| >
| >
| >
|
|
Nov 16 '05 #3

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

Similar topics

3
by: SLEEPY LOLO | last post by:
Hi! I have static function and three threads. I would like every thread to use this function at the same time. Is it possible? I'm using VC++ under Windows2000. Thanks Hubert
5
by: Marijn | last post by:
I'd like to know how compilers usually handle static variables that are declared inside a function (as opposed to static class-members). Like in: int counter(){ static int c=0; ++c; return c;...
10
by: Gernot Frisch | last post by:
Problem: A.cpp: ------ static FOO* gFoo=NULL; A.h extern FOO* gFoo; gives: L2001 - unresolved external: "symbol struct FOO* gFoo"
16
by: Eric | last post by:
I have a static class member variable as follows: struct A { static void Set (int i) { v = i; } static int& Get () { return v; } static int v; }; int A::v; // define A::v in the cpp file
115
by: Mark Shelor | last post by:
I've encountered a troublesome inconsistency in the C-language Perl extension I've written for CPAN (Digest::SHA). The problem involves the use of a static array within a performance-critical...
10
by: Peter Kirk | last post by:
Hi there I have a question about static variables. There is a function which returns a pointer to a structure "AStructure". The function has a static local variable of type AStructure, and it is...
2
by: JackRazz | last post by:
I'm trying to serialize a class using the binary formatter without serializing the 'static pastFirstCall as Boolean' variable. Normally private (module-scope) variables are serialized unless the...
20
by: Aek | last post by:
We recently moved our large codebase over from VS7 to 8 and found that we now get access violations in atexit calls at shutdown when debugging the application in VS2005. This occurs in static...
5
by: Lawrence Krubner | last post by:
Do any problems come up when using a static variable in a cron job? Assuming the cron job is called every 5 minutes for one year. Assume I've got an array that stores the names of which users are...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.