Problem with remote enum in VB.NET

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi!
My client fetches an object from the remote server. The client clones the
object and proceedes with its client processing.
If I don't clone the object each use of the object results in requests to
the server via the BinaryFormatterSink. Sometimes this produces a
RemoteException.
So, therefore I clone the object in the client. But I still get problem with
an enum member in the object, refering the enum member causes trafic to the
server via the BinaryFormatterSink which results in a RemoteException.

That leeds to the question: how to clone an enum member in a class?
Consider this:

Public Class MyClass
Public Enum MyEnum As Integer
A = 1
B = 2
End Enum

Public Id as Integer
Public Name as String
Public State as MyEnum

Public Function Clone() as MyClass
Dim o as New MyClass
o.Id = Id
o.Name = String.Copy(Name)
o.State = State 'this is not a clone! enums are
reference type
return o
End Function
End Class

How to clone the State enum?

A more detailed description of my problem:
--------------------------------------------------
There is a RemoteException thrown from the server when I log the state in
the client:
Debug.WriteLine("Current state = " & myObject.State.ToString())
The state.tostring() causes trafic to the server resulting in a
RemoteException.
If comment the trace line everything works fine!

What happens and what should I do???
 
Actually, enums are value types, not reference types, so just assigning
it to another enum should do the trick. I'm not sure why you get
RemoteException though, what do the stack trace and message look like?
 
I am going to go out on a limb here with both my knowledge of your issue and
my knowledge of my solution and of VB.NET....

I know there are issues with enums when they are compiled in separate
assemblies that use non default numbering sequences. Try it without
assigning values to your enum types.

-Andrew
 
Hi!
I thought also that the enum was a value type but when this occured it
seemed that it wasn't. It seems that the compiler uses the system.enum class
for the enumerations and then it must be of reference type. Also I'm using
the enum.ToString() method writing the name of the enumeration.


The RemoteException I get looks like:
---- Exception = System.Runtime.Remoting.RemotingException
-------------------------------------------------------
Message = Requested Service not found
Time = 2005-11-04 12:32:32
Class = SIEMENS.CMSbackup.Client.Client
Method = clientTimer_Elapsed
Target C = System.Runtime.Remoting.Channels.BinaryServerFormatterSink
Target M = ProcessMessage

Trace =

Server stack trace:
at
System.Runtime.Remoting.Channels.BinaryServerFormatterSink.ProcessMessage(IServerChannelSinkStack
sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream
requestStream, IMessage& responseMsg, ITransportHeaders& responseHeaders,
Stream& responseStream)

Exception rethrown at [0]:
at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate
method, Object[] args, Boolean synchronous)
at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)
at SIEMENS.CMSbackup.Client.Client.HandleNewManualReportState() in
C:\Local\CMS\Tools\CMSbackup\Client\Client.vb:line 396
at SIEMENS.CMSbackup.Client.Client.clientTimer_Elapsed(Object sender,
ElapsedEventArgs e) in C:\Local\CMS\Tools\CMSbackup\Client\Client.vb:line 248

After the client has fetched the object from the server and cloned it
processing of the object is handled in another thread by using a timer. That
thread sends the object to the UI via the Form.Invoke() method. And here the
RemoteException is thrown as you can see above.

For me it seems very strange, the application was in a release candidate
state and deeply tested with only minor bugs. We then added a string member
in the remote object and then this happened.
 
Hi,
now I've tried that but it doesn't help, the RemoteException is still
thrown...
--
Regards,
Lars Jönson


Andrew Robinson said:
I am going to go out on a limb here with both my knowledge of your issue and
my knowledge of my solution and of VB.NET....

I know there are issues with enums when they are compiled in separate
assemblies that use non default numbering sequences. Try it without
assigning values to your enum types.

-Andrew
 
Hi

Have you tried to change the enum type as a int type in your class and do
the same job as now, will the exception be thrown?
If yes, can you built a simple reproduce solution and send to me via
removing "online" from my email address?


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top