Enumerations are emitted as literals in the metadata.  This is great for
performance but has versioning problems.  In this particular case, you've
placed the enumerations in a separate assembly that both client and server
code reference. Once the client and server assemblies are compiled, YOU CAN
DELETE THE DLL WITH THE ENUMERATION DEFINITION FROM THE DISK! as the client
and server assemblies now have the enumerations in there respective
manifests AS LITERALS.  They don't reference the satellite assembly at
runtime.
If you need to change the enumeration definition, you'll have to recompile
both the client and server.
Note: This holds true for constants also.





From: Matthew Merrill <[EMAIL PROTECTED]>
Reply-To: "Moderated discussion of advanced .NET topics."
<[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
Subject: Re: [ADVANCED-DOTNET] Remoting fails with Enumeration fields
Date: Fri, 7 Feb 2003 13:44:30 -0800

Here is a reply that I have received from Microsoft.  This approach will
not allow the client to use the new syntax when instantiating the remote
object.

Attaching the modifed sample that works with RemoteTest_Meta.dll  stub in
the client.

Create the stub as below in RemoteTest_Meta.dll

namespace Server
{
             [Serializable]
             public enum DayOfWeek
             {
                  Sunday = 0,
                  Monday = 1,
                  Tuesday = 2,
                  Wednesday = 3,
                  Thursday = 4,
                  Friday = 5,
                  Saturday = 6
             };

         public interface IRemoteTest
         {


                  string doSomething();
                  string doSomething(DayOfWeek weekday);

         }
}



Reference RemoteTest_Meta.dll in both  Client as well as  RemoteTest.dll

Your RemoteTest looks like below.

 public class RemoteTest :MarshalByRefObject, Server.IRemoteTest
 {
      public RemoteTest()
      {
      }

      public string doSomething()
      {
         Console.WriteLine("doSomething() called");
         return "someValue";
      }

      public string doSomething(DayOfWeek weekday)
      {
         Console.WriteLine("doSomething(DayOfWeek) called");
         return Enum.GetName(typeof(DayOfWeek), weekday);
      }

}


Now in the Client  create the object using
         TcpChannel chnl = new TcpChannel();
         ChannelServices.RegisterChannel(chnl);

         Console.WriteLine("Client.Main(): creating rem. reference");
         IRemoteTest server = (IRemoteTest) Activator.GetObject(
typeof(IRemoteTest),
            "tcp://localhost:1234/RemoteTest.rem");



thanks,
liju, Microsoft.


In addition to the above solution, I have found that if you create a
separate satellite assembly containing only the enumerations that is
referenced by both the Server Remote object and the client, then the
method call succeeds.

Matthew

_________________________________________________________________
The new MSN 8: smart spam protection and 2 months FREE*
http://join.msn.com/?page=features/junkmail

Reply via email to