Click here to Skip to main content
15,912,578 members
Home / Discussions / C#
   

C#

 
GeneralRe: Dataset Filter Interger Pin
Orina DCosta29-Jun-04 20:20
Orina DCosta29-Jun-04 20:20 
GeneralRe: Dataset Filter Interger Pin
Antonius_r330-Jun-04 2:55
Antonius_r330-Jun-04 2:55 
GeneralRe: Dataset Filter Interger Pin
Antonius_r33-Jul-04 5:04
Antonius_r33-Jul-04 5:04 
GeneralRe: Dataset Filter Interger Pin
mikasa12-Jul-04 5:59
mikasa12-Jul-04 5:59 
GeneralSerializing, add new member var problem. Pin
Steve Schaneville29-Jun-04 3:28
professionalSteve Schaneville29-Jun-04 3:28 
GeneralRe: Serializing, add new member var problem. Pin
turbochimp29-Jun-04 4:45
turbochimp29-Jun-04 4:45 
GeneralRe: Serializing, add new member var problem. Pin
Steve Schaneville6-Jul-04 2:59
professionalSteve Schaneville6-Jul-04 2:59 
GeneralRe: Serializing, add new member var problem. Pin
Heath Stewart29-Jun-04 6:30
protectorHeath Stewart29-Jun-04 6:30 
In addition to what the 'chimp said, there's actually a better way that is verion-independent. First, if you correctly version your assemblies (as you should, just don't use automatic versioning a la an asterisk in your [assembly: AssemblyVersionAttribute]) you'll have another problem: the serialized form won't deserialize into a newer version (the types don't match, because the versions are different).

This is where a SerializationBinder comes into play. You extend the SerializationBinder and override BindToType. This gives you a chance to "redirect" versions. What I typically do is take the assembly string (includes name, version, culture info, and public key token) and strip out everything but the version. I then concat the typename and left-over assembly name to get a version-independent type. When you then get the Type, the latest version of the assembly is loaded and the new Type is returned. This new version of your existing class would contain the new field (not "variable", which is declared within a method itself), so you may still have to use the 'chimp's suggestion of implementing ISerializable (typically a good idea when you want better control over serialization anyway).

Below is a snippet of code showing what I mentioned:
public class DiffVersionBinder : SerializationBinder
{
  public override Type BindToType(string assemblyName, string typeName)
  {
    string name = assembly.Name.Substring(0, assemblyName.IndexOf(','));
    Type t = Type.GetType(typeName + ", " + name);
    return t;
  }
}
To use:
IFormatter formatter = new SoapFormatter();
formatter.Binder = new DiffVersionBinder();
object obj = formatter.Deserialize(someStream);


 

Microsoft MVP, Visual C#
My Articles
GeneralRe: Serializing, add new member var problem. Pin
Steve Schaneville6-Jul-04 3:01
professionalSteve Schaneville6-Jul-04 3:01 
GeneralTrackbar with multiple scrollers Pin
fp1229-Jun-04 3:07
fp1229-Jun-04 3:07 
GeneralRe: Trackbar with multiple scrollers Pin
Heath Stewart29-Jun-04 6:20
protectorHeath Stewart29-Jun-04 6:20 
GeneralRotating Pin
sreejith ss nair29-Jun-04 1:40
sreejith ss nair29-Jun-04 1:40 
GeneralRe: Rotating Pin
Dave Kreskowiak29-Jun-04 4:48
mveDave Kreskowiak29-Jun-04 4:48 
Generalusing unsafe code in c# Pin
Gobu SK29-Jun-04 1:33
Gobu SK29-Jun-04 1:33 
GeneralRe: using unsafe code in c# Pin
lesnikowski29-Jun-04 2:19
lesnikowski29-Jun-04 2:19 
GeneralRe: using unsafe code in c# Pin
Gobu SK29-Jun-04 2:48
Gobu SK29-Jun-04 2:48 
GeneralRe: using unsafe code in c# Pin
Gobu SK29-Jun-04 4:47
Gobu SK29-Jun-04 4:47 
GeneralNewline in Textbox Pin
matthias s.29-Jun-04 1:09
matthias s.29-Jun-04 1:09 
GeneralRe: Newline in Textbox Pin
lesnikowski29-Jun-04 1:25
lesnikowski29-Jun-04 1:25 
GeneralRe: Newline in Textbox Pin
matthias s.29-Jun-04 1:37
matthias s.29-Jun-04 1:37 
GeneralRe: Newline in Textbox Pin
Roland Bär29-Jun-04 3:07
Roland Bär29-Jun-04 3:07 
GeneralThe controls in Parent form are shown above the child form Pin
Vipingn29-Jun-04 0:11
Vipingn29-Jun-04 0:11 
GeneralRe: The controls in Parent form are shown above the child form Pin
Dave Kreskowiak29-Jun-04 4:34
mveDave Kreskowiak29-Jun-04 4:34 
QuestionHow to obtain the exe name "iexplore.exe" of Internet Explorer using Process class Pin
ganeshvijay29-Jun-04 0:04
ganeshvijay29-Jun-04 0:04 
AnswerRe: How to obtain the exe name "iexplore.exe" of Internet Explorer using Process class Pin
turbochimp29-Jun-04 5:12
turbochimp29-Jun-04 5:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.