Results 1 to 16 of 16

Thread: serialize/deserialize problem [UnResolved]

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    serialize/deserialize problem [UnResolved]

    Hi!

    ok, new to this. awesome stuff!

    I am basically serializing objects in xml from a Server app to a client app. the client app takes this xml serialized object and deserializes it.

    yes, both ends have the EXACT SAME class I am working with.

    when the client tries to deserialize the object, I get an invalidoperationexception (nullreference) - no idea why.

    this is the stack trace:

    System.InvalidOperationException was unhandled
    Message="An error message cannot be displayed because an optional resource assembly containing it cannot be found"
    StackTrace:
    at System.Xml.Serialization.XmlSerializer.Deserialize()
    at System.Xml.Serialization.XmlSerializer.Deserialize()
    at System.Xml.Serialization.XmlSerializer.Deserialize()
    at SomeApp.IncomingData.DoHandleIncomingXml()
    at SomeApp.IncomingData.DoAnalyzeData()
    at SomeApp.Communication.DoListenToIncomingPort()
    I have only chosen to serialize some properties but not all, however this should be ok no?


    This problem has been resolved, this is the new problem:

    how do you read a string into a stream in order to pass it to the deserializer? Opening and writing to a file is not an option unfortunatly
    Last edited by Techno; Mar 12th, 2006 at 08:18 AM.

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  2. #2
    Hyperactive Member Rattlerr's Avatar
    Join Date
    Jul 2005
    Location
    FloralCity,Florida
    Posts
    269

    Re: serialize/deserialize problem

    Since your Serializing only a few..Try Serializing all of them...

    Also in your using System do you have

    using System.Web; or using System.Web.UI; ?
    Might want to include "using System.Net;" also
    Check your "using"

    Also you might want too add ::
    using System.Diagnotics;

    in their if you dont already have it...

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: serialize/deserialize problem

    all the name spaces are there

    tried to serialize all objects (Except for arraylist otherwise exception will be thrown when serializing it) and i still get the exception!

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  4. #4
    Hyperactive Member Rattlerr's Avatar
    Join Date
    Jul 2005
    Location
    FloralCity,Florida
    Posts
    269

    Re: serialize/deserialize problem

    Ok what about your References? is System.Web in their?? I have noticed even if you have the using and dont include what your using in the References it will cause problems..

    From what your saying it sounds like your missing a Reference...Add the
    System.Web into ther References folder itself..

    Also might want to make a Folder for the xml file if you havent already and include into the project...example
    Code:
    using (blahblah.xml)

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: serialize/deserialize problem

    im not using ASP.NET, just a standard C# winform application
    ive also tried the suggestion but did not work

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  6. #6
    Hyperactive Member Rattlerr's Avatar
    Join Date
    Jul 2005
    Location
    FloralCity,Florida
    Posts
    269

    Re: serialize/deserialize problem

    ok what type of Serialization are you using??

    BinaryFormatter
    SoapFormatter
    XmlSerialization???

    here are some using examples

    using System.Runtime.Serialization.Formatters.Binary;

    using System.Xml.Serialization;

    Code:
    // Example
    
    public interface IFormatter
    {
    SerializationBinder{get; set;}
    StreamingContext Context {get; set;}
    ISurrogateSelector SurrogateSelector {get; set;}
    object Deserialize(System.IO.stream serializationStream);
    void Serialization(System.IO.Stream serializationStream, object graph);
    }
    The System.Runtime.Serialization.IFormatter defines the core Serialize() and Deserialize() methods,which do the grunt work...

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: serialize/deserialize problem

    hmmm think i solved the problem but that was testing stuff... moving away

    tell me, how would YOU Deserialize xml? Give me your code to deserialize an xml object.

    im using XmlSerialization

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: serialize/deserialize problem

    nevermind solved it

    it was the way i was reading etc.. was reading the saved xml serialized file to a memoryReader and then doing other stuff... bleh.

    this is the way to do it:

    Code:
    StreamReader sr = new StreamReader("blah.xml");
    YourClass temp = new YourClass();
    XmlSerializer serializer = new XmlSerializer(YourClass.GetType());
    temp = (YourClass)serializer.Deserialize(sr);
    sr.Close();

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  9. #9
    Hyperactive Member Rattlerr's Avatar
    Join Date
    Jul 2005
    Location
    FloralCity,Florida
    Posts
    269

    Re: serialize/deserialize problem

    [CODE]
    public interface IFormatter
    {
    object Deserialize(System.IO.Stream serializationStream);
    void Serialize(System.IO.Stream serializationStream, object //put your object here);
    }

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: serialize/deserialize problem [Resolved]

    actually for a minute lets reopen this thread. Stupid me, forgot what I was doing in the first place!!!!!!

    since I am serializing xml over the networkstream, client recieves it in a string.

    so how can I deserialize the string????

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  11. #11
    Hyperactive Member Rattlerr's Avatar
    Join Date
    Jul 2005
    Location
    FloralCity,Florida
    Posts
    269

    Re: serialize/deserialize problem [Resolved]

    Example
    Hope this Helps..
    Code:
    [Serializable]
    class MoreData
    {
    public string dataItemOne, dataItemTwo;
    [OnDeserializing] 
    internal void OnDeserializing(StreamingContext context)
    {
    dataItemOne = dataItemOne.ToLower();
    dataItemTwo = dataItemTwo.ToLower();
    }
    }
    // Either [OnDeserializing] or [OnDeserialized]

  12. #12

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: serialize/deserialize problem [Resolved]

    whats this example for?

    I need one where I can deserialize a string given to me since the serializer will be writing to a networkstream, so i need to deserialize the string given

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  13. #13
    Hyperactive Member Rattlerr's Avatar
    Join Date
    Jul 2005
    Location
    FloralCity,Florida
    Posts
    269

    Re: serialize/deserialize problem [Resolved]

    Post up the Code you need Deserialized so i can see what i'm working with...lol

  14. #14

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: serialize/deserialize problem [Resolved]

    The Server uses the xml serialize to WRITE TO NETWORKSTREAM, not a file.
    The Client recieves the content in string.
    The Client then calls a method to deserialize the xml - the string that has been sent:

    ok...



    Code:
    private void DoDeserializeXml(string theDataSentFromServer)
    {
       //thats it! the entire code lol. 
    }

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  15. #15
    Hyperactive Member Rattlerr's Avatar
    Join Date
    Jul 2005
    Location
    FloralCity,Florida
    Posts
    269

    Re: serialize/deserialize problem [UnResolved]

    Well m8 i tried my best the only thing i can think of to cause the exception is its not reading the NetworkStream....Because the Exception mentions a Resource Assembly....That tells me its not seeing the Source Assembly...

  16. #16

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: serialize/deserialize problem [UnResolved]

    Thanks mate but that's not what the problem is
    I have SOLVED the exception, but need to know HOW to convert string into a format I can give the deseralizer (i.e a Stream)

    thanks tho! Much appreciated

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width