[Mono-list] Problem with XML-Serialization

Atsushi Eno atsushieno at veritas-vos-liberabit.com
Tue Jul 14 21:04:25 EDT 2009


Let's please file a bug on our bugzilla. I'll have a look.
http://mono-project.com/Bugs

Atsushi Eno

Blackskyliner wrote:
> I serialize this class via the XML Serializer:
> 
> 
> class XMLStringSerializer
>     {
>         public static string Serialize<T>(T entity)
>         {
>             return Serialize(entity, true);
>         }
> 
>         public static string Serialize<T>(T entity, bool noNewLine)
>         {
>             StringBuilder outputXml = new StringBuilder();
> 
>             if (typeof(T).IsSerializable)
>             {
>                 XmlSerializer ser = new XmlSerializer(typeof(T));
>                 using (TextWriter stream = new StringWriter(outputXml))
>                 {
>                     ser.Serialize(stream, entity);
>                 }
>                 if (noNewLine)
>                     return outputXml.ToString().Replace(Environment.NewLine,
> "");
>                 else
>                     return outputXml.ToString();
>             }
> 
>             return null;
>         }
> 
>         public static T Deserialize<T>(string xml)
>         {
>             T entity;
> 
>             if (typeof(T).IsSerializable)
>             {
>                 XmlSerializer ser = new XmlSerializer(typeof(T));
>                 using (TextReader stream = new StringReader(xml))
>                 {
>                     entity = (T)ser.Deserialize(stream);
>                 }
> 
>                 return entity;
>             }
> 
>             return default(T);
>         }
>     }
> 
> 
> 
> 
> 
> Atsushi Eno-3 wrote:
>> Hi,
>>
>> Your subject implies it is about xml serialization, but it is
>> marked as [Serializable]. Which "serialization" do you mean?
>> XML serialization, or remoting SOAP serialization?
>>
>> Atsushi Eno
>>
>>
>> Blackskyliner wrote:
>>> Hi I just jumped in into mono I hope I'm in the right forum/mailinglist,
>>> because i wrote an little server application that I wanted to run on my
>>> linux machine. Its originally written in .NET 2.0
>>>
>>> To exchange Messages between Server and Client I use an XML-serialized
>>> class....
>>> In .NET I dont get any problems but with mono I get the following
>>> exception:
>>>
>>>  There was an error generating the XML document. > The type of the
>>> argument
>>> object 'ChatClient.serverMessages' is not primitive.
>>>
>>> I implemented the serverMessage in the following way:
>>>
>>> using System;
>>> using System.Text;
>>>
>>> namespace ChatClient
>>> {
>>>     [Serializable]
>>>     public class Message
>>>     {
>>>         public Message_StatusCodes statusCode;
>>>         public messageType messageType;
>>>         public object message;
>>>         public DateTime time;
>>>         public string user;
>>>
>>>         public Message()
>>>         {
>>>             init();
>>>         }
>>>
>>>         public Message(string Username)
>>>         {
>>>             init();
>>>             this.user = Username;
>>>         }
>>>
>>>         private void init(){
>>>             this.statusCode = Message_StatusCodes.NULL;
>>>             this.message = null;
>>>             this.time = DateTime.Now;
>>>             this.user = null;
>>>             this.messageType = messageType.NULL;
>>>         }
>>>
>>>         public void Clear()
>>>         {
>>>             this.statusCode = Message_StatusCodes.NULL;
>>>             this.messageType = messageType.NULL;
>>>             this.message = null;
>>>             this.time = DateTime.Now;
>>>             this.user = null;
>>>         }
>>>
>>>         public void Clear(string Username)
>>>         {
>>>             this.Clear();
>>>             this.user = Username;
>>>         }
>>>
>>>         public Message(Message_StatusCodes c)
>>>         {
>>>             init();
>>>             this.statusCode = c;
>>>         }
>>>     }
>>>
>>>     public enum Message_StatusCodes
>>>     {
>>>         NULL,
>>>
>>>         Login,
>>>
>>>         UserKicked,
>>>         UserJoined,
>>>         UserConnected,
>>>         UserDisconnected,
>>>
>>>         UserListChanged
>>>     }
>>>
>>>     public enum messageType{
>>>         NULL,
>>>         UserMessage,
>>>         ServerMessage,
>>>         ClientMessage
>>>     }
>>>
>>>     public enum serverMessages
>>>     {
>>>         LOGIN_ERROR_UserAlreadyExist,
>>>         LOGIN_ERROR_UsernameReserved,
>>>         LOGIN_OK
>>>     }
>>>
>>>     public enum clientMessages
>>>     {
>>>         Disconnect
>>>     }
>>> }
>>>
>>>
>>> Why does this not deserialize in Mono but in C#?? Is there any workaround
>>> or
>>> smth. else?
>>>
>>> I'm thankful about every answer...
>>> Blackskyliner
>> _______________________________________________
>> Mono-list maillist  -  Mono-list at lists.ximian.com
>> http://lists.ximian.com/mailman/listinfo/mono-list
>>
>>
> 



More information about the Mono-list mailing list