From 915662c45c24acc219818c0c17dba6eb2a7e7cad Mon Sep 17 00:00:00 2001 From: Esme Povirk Date: Tue, 19 Sep 2023 14:31:25 -0500 Subject: [PATCH] corlib: Allow reregistering services. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=45144 --- .../Test/RemotingServicesTest.cs | 55 +++++++++++++++++++ .../RemotingServices.cs | 3 - 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/mcs/class/System.Runtime.Remoting/Test/RemotingServicesTest.cs b/mcs/class/System.Runtime.Remoting/Test/RemotingServicesTest.cs index d5e1e44a500e..409212e79468 100644 --- a/mcs/class/System.Runtime.Remoting/Test/RemotingServicesTest.cs +++ b/mcs/class/System.Runtime.Remoting/Test/RemotingServicesTest.cs @@ -379,6 +379,61 @@ public void ExecuteMessage () } } + [Test] + public void Reregister () + { + var port = NetworkHelpers.FindFreePort (); + IDictionary props = new Hashtable (); + props ["port"] = port; + props ["bindTo"] = "127.0.0.1"; + TcpChannel chn = new TcpChannel (props, null, null); + ChannelServices.RegisterChannel (chn); + try { + MarshalObject objMarshal = NewMarshalObject (); + + RemotingConfiguration.RegisterWellKnownServiceType (typeof (MarshalObject), objMarshal.Uri, WellKnownObjectMode.SingleCall); + bool found = false; + foreach (WellKnownServiceTypeEntry entry in RemotingConfiguration.GetRegisteredWellKnownServiceTypes ()) + { + if (entry.ObjectUri == objMarshal.Uri) + { + Assert.AreEqual (WellKnownObjectMode.SingleCall, entry.Mode, "found 1"); + Assert.IsFalse (found, "found 1"); + found = true; + } + } + Assert.IsTrue (found, "found 1"); + + RemotingConfiguration.RegisterWellKnownServiceType (typeof (MarshalObject), objMarshal.Uri, WellKnownObjectMode.SingleCall); + found = false; + foreach (WellKnownServiceTypeEntry entry in RemotingConfiguration.GetRegisteredWellKnownServiceTypes ()) + { + if (entry.ObjectUri == objMarshal.Uri) + { + Assert.AreEqual (WellKnownObjectMode.SingleCall, entry.Mode, "found 2"); + Assert.IsFalse (found, "found 2"); + found = true; + } + } + Assert.IsTrue (found, "found 2"); + + RemotingConfiguration.RegisterWellKnownServiceType (typeof (MarshalObject), objMarshal.Uri, WellKnownObjectMode.Singleton); + found = false; + foreach (WellKnownServiceTypeEntry entry in RemotingConfiguration.GetRegisteredWellKnownServiceTypes ()) + { + if (entry.ObjectUri == objMarshal.Uri) + { + Assert.AreEqual (WellKnownObjectMode.Singleton, entry.Mode, "found 3"); + Assert.IsFalse (found, "found 3"); + found = true; + } + } + Assert.IsTrue (found, "found 3"); + } finally { + ChannelServices.UnregisterChannel (chn); + } + } + // Tests the IsOneWay method [Test] public void IsOneWay () diff --git a/mcs/class/corlib/System.Runtime.Remoting/RemotingServices.cs b/mcs/class/corlib/System.Runtime.Remoting/RemotingServices.cs index 6255bfff6533..0e291e615a29 100644 --- a/mcs/class/corlib/System.Runtime.Remoting/RemotingServices.cs +++ b/mcs/class/corlib/System.Runtime.Remoting/RemotingServices.cs @@ -737,9 +737,6 @@ private static void RegisterServerIdentity(ServerIdentity identity) { lock (uri_hash) { - if (uri_hash.ContainsKey (identity.ObjectUri)) - throw new RemotingException ("Uri already in use: " + identity.ObjectUri + "."); - uri_hash[identity.ObjectUri] = identity; } }