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 9281551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T18:08:58+00:00 2026-06-18T18:08:58+00:00

I am using C# remoting for accessing a Label on the server system and

  • 0

I am using C# remoting for accessing a Label on the server system and the text of that label is to be changed by the click of a button on the client system. I have made a remotable object in a class library naming RemoteObject and added the reference of this class library to both client and server system but when debugging both the server system and client system I am getting the exception “Only one usage of each socket address (protocol/network address/port) is normally permitted”

Please help me in this to rectify this issue..

RemotableObject.dll

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RemoteObject
{
    public class Class1 : MarshalByRefObject
    {
        public Class1()
        {
        }

        public void setText()
        {
            ServerClass bs = new ServerClass();
            Label lbl = bs.Controls["label1"] as Label;
            lbl.Text = "New Text";
        }
    }
}

Server Side Code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using RemoteObject;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

namespace Server
{
    public partial class ServerClass : Form
    {
        private Class1 myremoteobject;
        public ServerClass()
        {
            InitializeComponent();
            myremoteobject = new Class1();
            TcpChannel channel = new TcpChannel(30000);
            ChannelServices.RegisterChannel(channel, true);
            RemotingConfiguration.RegisterWellKnownServiceType(typeof(Class1), "CSBU", WellKnownObjectMode.SingleCall);
        }

    }
}

Client Side Code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using RemoteObject;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;


namespace Client
{
    public partial class ClientClass : Form
    {
        private Class1 remoteobject = new Class1();
        public ClientClass()
        {
            InitializeComponent();
            TcpChannel chan = new TcpChannel();
            ChannelServices.RegisterChannel(chan,true);
            remoteobject = (Class1)Activator.GetObject(typeof(Class1), "tcp://localhost:30000/CSBU");
        }

        private void changeTextBtn_Click(object sender, EventArgs e)
        {
            remoteobject.setText();
        }
    }
}

Please someone help me with the solution for this exception asap.

  • 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-18T18:08:59+00:00Added an answer on June 18, 2026 at 6:08 pm

    It looks like the problem is that your Class1.setText method creates a new ServerClass. Now since the thing that creates an instance of Class1, and makes it available via remoting, is ServerClass, presumably that means that by the time your setText method is invoked remotely, you’ve already got one instance of ServerClass, so that’ll end up creating a second.

    This means that all the code in the ServerClass constructor runs twice. The second time it runs, it’ll be attempting to register a new TcpChannel on port 30000 for the second time. Since the channel you created first time round is already running, you get the error you describe.

    Try putting a breakpoint on your ServerClass constructor, and I’d expect that you’ll see it run twice. The first time you won’t get the error, but the second time you will.

    The solution will be to avoid creating a new ServerClass in that setText method. If your intention is that the remoting call was supposed to modify a label in the form already on screen, then you need to pass a reference to the existing ServerClass instance to the Class1 instance. (E.g., make the Class1 constructor take a ServerClass as an argument, and store that in a field. Use that instead of constructing a new one in setText.)

    By the way, remoting is more or less deprecated. WCF is the usual way to do remote access in .NET these days. Either that or Web API.

    Update:013/02/12

    Sorry, it has been a while since I used Remoting because, as I mentioned, Remoting is deprecated and you shouldn’t be using it!

    So, the thing I forgot: Remoting doesn’t make it straightforward to register a particular well known instance – you register well-known types and Remoting wants to construct the type for you. So you’ll need to come up with some other way of passing the ServerClass to your Class1.

    E.g.:

    public class Class1 : MarshalByRefObject
    {
        public static ServerClass MyServer { get; set; }
    
        public void setText()
        {
            ServerClass bs = MyServer;
            Label lbl = bs.Controls["label1"] as Label;
            lbl.Text = "New Text";
        }
    }
    

    and then your ServerClass becomes:

    public partial class ServerClass : Form
    {
        public ServerClass()
        {
            InitializeComponent();
    
            Class1.MyServer = this;
    
            TcpChannel channel = new TcpChannel(30000);
            ChannelServices.RegisterChannel(channel, true);
            RemotingConfiguration.RegisterWellKnownServiceType(typeof(Class1), "CSBU", WellKnownObjectMode.SingleCall);
        }
    }
    

    Then you’ll hit your next error, an InvalidOperationException with the error “Cross-thread operation not valid: Control ‘label1’ accessed from a thread other than the thread it was created on.”

    This is because Remoting calls come in on worker threads, but you must only update Windows Forms UI elements from their owning UI thread.

    Again, please don’t use this because, as I may have mentioned before REMOTING IS DEPRECATED AND YOU SHOULDN’T BE USING IT; USE WCF but for what it’s worth, here’s how to deal with that:

    public void setText()
    {
        MyServer.BeginInvoke((Action) setTextOnUiThread);
    }
    
    private void setTextOnUiThread()
    {
        ServerClass bs = MyServer;
        Label lbl = bs.Controls["label1"] as Label;
        lbl.Text = "New Text";
    }
    

    And that should work.

    And one more time, DON’T DO THIS – REMOTING IS NO LONGER A CURRENT TECHNOLOGY. LOOK AT WCF INSTEAD

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

Sidebar

Related Questions

I have a server-side code using .NET Remoting to establish the connection with client.
I have a client and server communicating via Spring remoting (using Java Serialization) over
I am developing a client-server application using .Net Remoting. From my server I want
When using .net remoting, does the server limit incoming client remoting calls? I find
We're using .NET Remoting with a Client/Shared/Server architecture where: Shared DLL: common to both
This is my Hello World Remoting App. using System; using System.Collections.Generic; using System.Text; namespace
I have this code: using System; using System.Runtime.Remoting.Messaging; class Program { static void Main(string[]
When using IPython, osx terminal and remoting into an ubuntu server. I noticed that
We have a very old windows forms application that communicates with the server using
I have a complex .NET Remoting server app that provides a couple of services.

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.