Returning an Enum From A Remote Service?

  • Thread starter Thread starter David White
  • Start date Start date
D

David White

I have a C# client and a C# remote service. I want to return an enum from the
service to the client. I have defined the enum in a shared DLL referenced by
both client and server which also contains the shared interface. But when the
code runs (on .Net 2 on XP anyway), it fails with an exception "return argument
has an invalid type". If I return an int, no problem. Seems like this should
work. Any pointers? Thanks.
 
Hi David,
I haven't really tried this but is your enum serializable?...
[Serializable]

Just maybe.
 
Thanks for the idea. I figured this would not be needed as the enum is
implemented via an integer type. In the docs it says that if serialization is a
problem a specific, serialization-related exception should be thrown. I don't
get that. Anyhow, I tried marking the enum with [Serializable], rebuilt, and
tried again on your hunch. No change. But thanks.

Hi David,
I haven't really tried this but is your enum serializable?...
[Serializable]

Just maybe.


I have a C# client and a C# remote service. I want to return an enum from
the service to the client. I have defined the enum in a shared DLL
referenced by both client and server which also contains the shared
interface. But when the code runs (on .Net 2 on XP anyway), it fails with
an exception "return argument has an invalid type". If I return an int, no
problem. Seems like this should work. Any pointers? Thanks.
 
BTW - I also found examples of Serializable annotations in the form
[Serializable()] I am not sure there is any difference between this and
[Serializable] (no parens). Both compile without complaint. Neither makes any
difference in my problem.

I decided to also try passing the enum into a remote function. I get an error
which reads something like, "due to access security..." and it fails. So I am
really confused now.

Any ideas?

David said:
Thanks for the idea. I figured this would not be needed as the enum is
implemented via an integer type. In the docs it says that if
serialization is a problem a specific, serialization-related exception
should be thrown. I don't get that. Anyhow, I tried marking the enum
with [Serializable], rebuilt, and tried again on your hunch. No change.
But thanks.

Hi David,
I haven't really tried this but is your enum serializable?...
[Serializable]

Just maybe.


I have a C# client and a C# remote service. I want to return an enum
from the service to the client. I have defined the enum in a shared
DLL referenced by both client and server which also contains the
shared interface. But when the code runs (on .Net 2 on XP anyway), it
fails with an exception "return argument has an invalid type". If I
return an int, no problem. Seems like this should work. Any pointers?
Thanks.
 
I decided to also try passing the enum into a remote function. I get
an error which reads something like, "due to access security..." and
it fails. So I am really confused now.

You shouldn't have any problems passing enums thru remoting. Can you post
a small and complete program that demonstrates the issue, as per Jon
Skeet's typical directives?

(See http://www.yoda.arachsys.com/csharp/complete.html)

-mdb
 
Michael,

Thanks for pushing me to do this obvious task. In my simple example, all works
just fine as you suggest. I am still trying to make if more like my "real"
program and I hope to eventually figure this out.

David
 
Back
Top