Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Problem in MessageQueue

Problem in MessageQueue

Scheduled Pinned Locked Moved C#
helpcsharpdata-structuresquestion
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rbarzallo
    wrote on last edited by
    #1

    Hi, i have next class : public class abc { public string campo 1; public string campo 2; public Socket CltSckt; public NetWorkStream NS; } After of initialize the class and stored the data for each variable, I wish to send or store in a Queue : public int EscribeCola(string SrvName, string QueueName, abc Msg_Devices) { try { MessageQueue msgq = new MessageQueue(); msgq.Formatter = new XmlMessageFormatter(new Type[] {typeof(string)}); System.Messaging.Message msg = new System.Messaging.Message(); msgq.Path = (SrvName + QueueName); // // coloco el mensaje en la cola lock(this) { msgq.Send(Mensaje_Devices); } msgq.Dispose(); return 0; } catch (Exception ex) { acc_evento.ReportaEvento(PROCESO_ORIGEN,Param_Eventos.PROBLEMA_WRITE_QUEUE, QueueName + " " + ex.Message + " " + ex.InnerException.Message); return -1; } } In the moment of "send", present a runtime error : "There was an error refecting 'Msg_Devices'" "System.net.sockets.socket" "Cannot be serialized because it does not have a default constructor". May you help me? What have I do? Grettings

    J 1 Reply Last reply
    0
    • R rbarzallo

      Hi, i have next class : public class abc { public string campo 1; public string campo 2; public Socket CltSckt; public NetWorkStream NS; } After of initialize the class and stored the data for each variable, I wish to send or store in a Queue : public int EscribeCola(string SrvName, string QueueName, abc Msg_Devices) { try { MessageQueue msgq = new MessageQueue(); msgq.Formatter = new XmlMessageFormatter(new Type[] {typeof(string)}); System.Messaging.Message msg = new System.Messaging.Message(); msgq.Path = (SrvName + QueueName); // // coloco el mensaje en la cola lock(this) { msgq.Send(Mensaje_Devices); } msgq.Dispose(); return 0; } catch (Exception ex) { acc_evento.ReportaEvento(PROCESO_ORIGEN,Param_Eventos.PROBLEMA_WRITE_QUEUE, QueueName + " " + ex.Message + " " + ex.InnerException.Message); return -1; } } In the moment of "send", present a runtime error : "There was an error refecting 'Msg_Devices'" "System.net.sockets.socket" "Cannot be serialized because it does not have a default constructor". May you help me? What have I do? Grettings

      J Offline
      J Offline
      Jeff Varszegi
      wrote on last edited by
      #2

      It's indicating that you can't serialize the Socket object, looks like to me; not only does it not have a default constructor, but it doesn't implement the ISerializable interface isn't marked with the SerializableAttribute attribute. What would be the value in serializing a socket, anyway? You can mark it with the [NonSerialized] attribute to avoid this problem. Regards, Jeff Varszegi EEEP!  An Extensible Expression Evaluation Package

      H R 2 Replies Last reply
      0
      • J Jeff Varszegi

        It's indicating that you can't serialize the Socket object, looks like to me; not only does it not have a default constructor, but it doesn't implement the ISerializable interface isn't marked with the SerializableAttribute attribute. What would be the value in serializing a socket, anyway? You can mark it with the [NonSerialized] attribute to avoid this problem. Regards, Jeff Varszegi EEEP!  An Extensible Expression Evaluation Package

        H Offline
        H Offline
        Heath Stewart
        wrote on last edited by
        #3

        To note, something doesn't have to implement ISerializable to be serializable - only to be attributed with the SerializableAttribute (not inheritted with the formatters provided in the FCL, as it should be). The interface is just to customize how an object is serialized. You're still right about the Socket class not being serializable, though. I mean, that's just silly! :)

        Microsoft MVP, Visual C# My Articles

        J 1 Reply Last reply
        0
        • H Heath Stewart

          To note, something doesn't have to implement ISerializable to be serializable - only to be attributed with the SerializableAttribute (not inheritted with the formatters provided in the FCL, as it should be). The interface is just to customize how an object is serialized. You're still right about the Socket class not being serializable, though. I mean, that's just silly! :)

          Microsoft MVP, Visual C# My Articles

          J Offline
          J Offline
          Jeff Varszegi
          wrote on last edited by
          #4

          Whoops, right you are. My Java undies are showing-- in Java the Serializable interface is just a marker interface, with Externalizable the one you implement to provide your own serialization routine. I get mixed up sometimes because some things are so similar in Java and .NET, and I still have to use both at work. I'm getting used to rapidly switching between naming and casing conventions, but the APIs still trip me up occasionally. Thanks for the correction. Regards, Jeff Varszegi EEEP!  An Extensible Expression Evaluation Package

          1 Reply Last reply
          0
          • J Jeff Varszegi

            It's indicating that you can't serialize the Socket object, looks like to me; not only does it not have a default constructor, but it doesn't implement the ISerializable interface isn't marked with the SerializableAttribute attribute. What would be the value in serializing a socket, anyway? You can mark it with the [NonSerialized] attribute to avoid this problem. Regards, Jeff Varszegi EEEP!  An Extensible Expression Evaluation Package

            R Offline
            R Offline
            rbarzallo
            wrote on last edited by
            #5

            I tried to put [NonSerialized] the class, but show me a compilation error. Please, may you send me an example?

            J 1 Reply Last reply
            0
            • R rbarzallo

              I tried to put [NonSerialized] the class, but show me a compilation error. Please, may you send me an example?

              J Offline
              J Offline
              Jeff Varszegi
              wrote on last edited by
              #6

              Don't put it on the class, just on the fields you don't want to serialize, like so: public class abc {     public string campo 1;     public string campo 2;     [NonSerialized]     public Socket CltSckt;      public NetWorkStream NS; } Try that and get back to me. -Jeff here, bloggy bloggy

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups