Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8294709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:19:07+00:00 2026-06-08T14:19:07+00:00

Type ‘System.Net.Sockets.Socket’ cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking

  • 0

Type ‘System.Net.Sockets.Socket’ cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute.

I am making a service in WCF which opens connection and send message to server but above error is given when i run the service . I do not know how to mark it with data contract attribute or how to solve the problem.

public class Service1 : IService1
{


    public void Connect(String a , String b)
    {

        int hit = Convert.ToInt32(a);

        int delay = Convert.ToInt32(b);
        delay = delay * 1000; 

 // I have eliminated the log making part       string LogPath = "C:\\VoltTestApp\\Logs\\";


        for (int i = 1; i <= hit; i++)
        {

            try
            {
                TcpClient tcpClient = new TcpClient("10.111.13.72", 80);
                Console.WriteLine("Initialized Socket  .............\n");
                Socket socket = tcpClient.Client;
                string str = "ID_T$";

                try
                { // sends the text with timeout 10s
                    Console.WriteLine("Going To Send Request  .............\n");
                    Send(socket, Encoding.UTF8.GetBytes(str.Trim()), 0, str.Length, 10000);
               }


                socket.Close();
                tcpClient.Close();
                Console.WriteLine("Socket Closed  .............\n");
            }

            Thread.Sleep(delay);
        }

    }



    public  void Send(Socket socket, byte[] buffer, int offset, int size, int timeout)
    {
        try
        {
            int startTickCount = Environment.TickCount;
            int sent = 0;  // how many bytes is already sent
            do
            {
                if (Environment.TickCount > startTickCount + timeout)
                    throw new Exception("Timeout.");
                try
                {
                    sent += socket.Send(buffer, offset + sent, size - sent, SocketFlags.None);
                }
                catch (SocketException ex)
                {
                    if (ex.SocketErrorCode == SocketError.WouldBlock ||
                        ex.SocketErrorCode == SocketError.IOPending ||
                        ex.SocketErrorCode == SocketError.NoBufferSpaceAvailable)
                    {
                        // socket buffer is probably full, wait and try again
                        Thread.Sleep(30);
                    }
                    else
                        throw ex;  // any serious error occurr
                }
            } while (sent < size);
        }

    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T14:19:10+00:00Added an answer on June 8, 2026 at 2:19 pm

    In this instance, it’s probably because you have a public method on your service which takes a Socket as a parameter. This is, quite naturally, not able to be serialized properly when attempting service discovery.

    If Send is only used internally, set it as private.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What Type System Version (Compatibility Level) token can I specify in ADO.NET connection string
System.Type contains an UnderlyingSystemType property. MSDN states that it: Indicates the type provided by
Type erasure - is that how you call it? How boost::shared_ptr stores its deleter
The type 'System.ComponentModel.DataAnnotations.MaxLengthAttribute' exists in both [path...]\packages\EntityFramework.4.3.1\lib\net40\EntityFramework.dll and 'c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework \.NETFramework\v4.5\System.ComponentModel.DataAnnotations.dll' Now,
Type.GetType(System.String) Is there a lookup for the aliases available somewhere? Type.GetType(string) returns null .
Type erasure is supposed to erase all generic information... If this is the case
Error: Type mismatch: cannot convert from Set<ConstraintViolation<capture#1-of ?>> to Set<ConstraintViolation<Class<?>>> My code: public class
What type of chart or what properties should I set in ASP.NET 4.0 chart
Type of conditional expression cannot be determined because there is no implicit conversion between
Consider type like this one public interface IHaveGenericMethod { T1 Method<T1>(T1 parm); T2 Method<T1,T2>(T1

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.