|
-
Mar 11th, 2006, 11:01 PM
#1
Thread Starter
PowerPoster
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.
-
Mar 11th, 2006, 11:34 PM
#2
Hyperactive Member
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...
-
Mar 11th, 2006, 11:39 PM
#3
Thread Starter
PowerPoster
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!
-
Mar 11th, 2006, 11:45 PM
#4
Hyperactive Member
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)
-
Mar 11th, 2006, 11:47 PM
#5
Thread Starter
PowerPoster
Re: serialize/deserialize problem
im not using ASP.NET, just a standard C# winform application
ive also tried the suggestion but did not work
-
Mar 12th, 2006, 12:00 AM
#6
Hyperactive Member
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...
-
Mar 12th, 2006, 12:04 AM
#7
Thread Starter
PowerPoster
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
-
Mar 12th, 2006, 12:12 AM
#8
Thread Starter
PowerPoster
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();
-
Mar 12th, 2006, 12:12 AM
#9
Hyperactive Member
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);
}
-
Mar 12th, 2006, 12:18 AM
#10
Thread Starter
PowerPoster
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????
-
Mar 12th, 2006, 12:30 AM
#11
Hyperactive Member
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]
-
Mar 12th, 2006, 12:39 AM
#12
Thread Starter
PowerPoster
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
-
Mar 12th, 2006, 12:43 AM
#13
Hyperactive Member
Re: serialize/deserialize problem [Resolved]
Post up the Code you need Deserialized so i can see what i'm working with...lol
-
Mar 12th, 2006, 12:48 AM
#14
Thread Starter
PowerPoster
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.
}
-
Mar 12th, 2006, 01:04 AM
#15
Hyperactive Member
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...
-
Mar 12th, 2006, 07:39 AM
#16
Thread Starter
PowerPoster
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|