Re: A serialization problem
From: Jared Parsons [MSFT] (jaredpar_at_online.microsoft.com)
Date: 06/16/04
- Next message: Jordan Wright: "Re: Accessing protected http"
- Previous message: Eric St-Onge: "Re: COM, GAC and Guidelines"
- In reply to: Mike: "A serialization problem"
- Next in thread: Mike: "Re: A serialization problem"
- Reply: Mike: "Re: A serialization problem"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 16 Jun 2004 10:49:33 -0700
You problem probably is a result of the data not being completely written to
disk. Try adding the following code to the end of the SaveSettings() method
fileStream.Flush();
fileStream.Close();
Also make sure you close the file stream after you load the serializaed
information.
-- Jared Parson [MSFT] jaredpar@online.microsoft.com This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm "Mike" <noone@hotmail.com> wrote in message news:uilCwN3UEHA.412@TK2MSFTNGP10.phx.gbl... > Hello. > > I am using C# in .NET v1.1. I am trying to serialize an object to disk and > read it back again. The serialization seems to work OK (at least, it > completes without error). However, I get the following error when trying to > deserialize: > > An unhandled exception of type > 'System.Runtime.Serialization.SerializationException' occurred in > mscorlib.dll > > Additional information: Binary stream does not contain a valid BinaryHeader, > 84 possible causes, invalid stream or object version change between > serialization and deserialization. > > My serialization code is as follows (this.Settings is an instance of the > serializable Persistant Settings class): > > > > public class MyApp : System.Windows.Forms.Form > { > // code stripped down... > > [Serializable] > public class PersistantSettings > { > // only 1 tyring to persist one object for now > public IList WatchdogToWatch; > > public PersistantSettings() > { > } > } > > public void SaveSettings() > { > FileStream fileStream = new > FileStream(System.Windows.Forms.Application.CommonAppDataPath > + SettingsFile, FileMode.OpenOrCreate, FileAccess.Write); > BinaryFormatter formatter = new BinaryFormatter(); > > this.Settings.WatchdogToWatch = toWatch; // both are declared as ILists > formatter.Serialize(fileStream, this.Settings); > } > > public bool LoadSettings() > { > FileStream fileStream; > BinaryFormatter formatter = new BinaryFormatter(); > bool fileExists = false; > > fileStream = new > FileStream(System.Windows.Forms.Application.CommonAppDataPath > + SettingsFile, FileMode.Open, FileAccess.Read); > > // this is the line that causes the error > PersistantSettings settings = > (PersistantSettings)formatter.Deserialize(fileStream); > // etc... > } > > //... > } > > > > Here is the binary file produced by the serialization (if this is any use): > > FUwcTelcoControl, Version=0.0.0.0, Culture=neutral, > PublicKeyToken=null)Uwc.TelcoControl.Form1+PersistantSettingsWatchdogToW > atchSystem.Collections.ArrayList > System.Collections.ArrayList_items_size_version > HUwcLibrary, Version=1.0.1628.30181, Culture=neutral, > PublicKeyToken=nullToken=null=nullUwc.Entities.RetailerMasterIdWholesal > erMasterIdTypeNameUwc.Entities.EntityType > YUwc.Entities.EntityTypevalue__ CH01 - Ring Phonecard > > CH02 - Lime PhonecardCH03 - Western Union > PhonecardTCH04 - Bharath > Phonecard card3CH03 - Western Union > PhonecardT5CH04 - Bharath > Phonecard8T7$GG01 - Global Gossip Phonecard (AUS) ? > 9GG02 - Global Community Card > <;GG03 - BTC TravelTribe <=GG04 - Global > Gossip TeleCard <?GG05 - Oz Experience Phonecard > <A"GG06 - Worldwide Workers PhonecardjCGG07 - > Nomads PhonecardkEGG08 - Buzz CardlGGG09 - > UWS Phonecard\IGG10 - StudentCard%)KGG11 - > UTS Phonecard%{MGG12 - Insearch > PhonecardOGG14 - Global Gossip > TeleCode*YQPC01 - Britz Phonecard+YSPC02 - > Maui Phonecard'UPC03 - Alpine > PhonecardWTEST - Test product6Y)U015 - > Backpackers World Travel Phonecard7[!U016 - Base Backpackers > PhonecardS]*U017 - Friendly Backpacker Group > PhonecardT_&U018 - Work & Travel Company Phonecard& > aU019 - Swagmail Phonecardo zc)U020 - Travellers > Contact Point Phonecardo oe)U021 - English Language Company > Phonecard T!sgU022 - CIEE International!" > !~i#U023 - Global Gossip Phonecard (US)")!-kU024 - > Internet Outpost#)!"mU025 - Unity Card$)!' > o'U026 - NEW Global Gossip Community > Card%Uwc.Entities.WholesalerMasterIdTypeNameUwc.Entities.EntityTyp > e//HqBharath Phonecard&%sZs > BudgetTel'%OuDEMO(%SSw > Global Gossip)%^yGlobal Gossip Phonecard > US*%!?{Global Gossip Venice Beach+%o"}Lime > Phonecard,%S,Promocom-%>?Ring > Phonecard.%~fWestern Union > Phonecard |.Promocom/'>z?Ring > Phonecard0'x?Western Union Phonecard > > > Any help would be greatlyt appreciated. > > Cheers, > > Mike > >
- Next message: Jordan Wright: "Re: Accessing protected http"
- Previous message: Eric St-Onge: "Re: COM, GAC and Guidelines"
- In reply to: Mike: "A serialization problem"
- Next in thread: Mike: "Re: A serialization problem"
- Reply: Mike: "Re: A serialization problem"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|