.NET Remoting, passing objects into methods
Asked Answered
C

3

8

I am writing a .NET Remoting application. I have my dll, server, and client all working correctly. However, when I try to change my method call to take an object parameter instead of a simple type like an int, it complains with this error.

Type System.Runtime.Remoting.ObjRef and the types from it (such as System.Runtime.Remoting.ObjRef) are not permitted to be deserialized at this security level.

The method is something like this.

public List<Orders> GetOrders(int UserID) { //Works

public List<Orders> GetOrders(Users user) { // Doesnt Work

[Serializable]
public class Users : MarshalByRefObject {

Now I have made the User class also, [Serializable] and given it MarshalByRefObject inheritance. Could this be my problem? I have tried removing [Serializable] from the User class and it complains cause it cant interpret it.

EDIT Ok, here is my client method.

IChannel channel = new TcpClientChannel();
ChannelServices.RegisterChannel(channel, false);
CustomType Server = (CustomType)Activator.GetObject(typeof(CustomType), "tcp://localhost:9934/CustomType");

Here is my server.

BinaryServerFormatterSinkProvider provider = new BinaryServerFormatterSinkProvider();
provider.TypeFilterLevel = TypeFilterLevel.Full;
IDictionary props = new Hashtable();
props["port"] = 9934;
TcpChannel channel = new TcpChannel(props, null, provider);
ChannelServices.RegisterChannel(channel);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(CustomType), "CustomType", WellKnownObjectMode.Singleton);
Console.WriteLine("Server is initialized");
Console.ReadLine();
Carnage answered 13/2, 2012 at 21:12 Comment(5)
Have you tried by removing MarshalByRefObject from Users class?Headman
I have not fully tried that let me go back and make sureCarnage
When I removed the MarshalByRefObject it didnt help, thanks!Carnage
Since you were the first to post the solution L.B I would give you credit if you create an Answer instead of a comment.Carnage
Thanks, knowing that you solved your problem is enough.Headman
C
1

Actually, .NET remoting is an obsolete technology. You should take a look at WCF instead.

Regarding your actual problem: Your probably running your application in a trust-level that is too low.
The Users class should be serializable, but, if it does not contain any methods that should run at the server, it should not derive from MarshalByRefObject

Cortese answered 13/2, 2012 at 21:17 Comment(4)
arguably, remoting still serves a usage for talking between AppDomains in the same process. Just sayin'Sherrilsherrill
I havent looked at WCF yet, and the User class doesnt hold any necessary calls that would need to inherit MarshalByRefObject. I was trying to go the simple route and create a single DLL that could be utilized for the Server and Client Application instead of creating multiple DLL's.Carnage
The practical problem with using an obsolete technology is that there are fewer people who remember it. I just barely remembered that I had seen this error before, but not how to fix it. And I'm old.Hollyanne
Lol ok well, I am young and wanting to embrace the latest and greatest so I should probably look into WCF and figure it out. Also, I dont want to run into major issues with my new app. So thanks for the heads up on this!Carnage
C
4

"are not permitted to be deserialized at this security level." is the significant part.

See the following for the answer

http://www.codeproject.com/Articles/4363/NET-Remoting-in-Simple-English-Really-it-s-that-s

Set the following on both client and server:

typeFilterLevel="Full" in the Formatter tag

Conspecific answered 13/2, 2012 at 21:22 Comment(3)
If I am not setting this up via a config file how do I perform this?Carnage
The answer is here: alexthissen.nl/blogs/main/archive/2007/12/23/…Conspecific
The provided link is broken. The new one is alexthissen.wordpress.com/2007/12/23/…Kappel
A
2

Ensure both the server and client configuration set the typeFilterLevel property to Full

or have your User class implement ISerializable

MSDN Documentation on .NET Remoting Serialization Security.

Agreeable answered 13/2, 2012 at 21:21 Comment(6)
Ok whenever I implement this, it gives me the following error when the method tries to hit the DB. This remoting proxy has no channel sink which means either the server has no registered server channels that are listening, or this application has no suitable client channel to talk to the server.Carnage
Let me be more specific, whenever it tries to access the User.UserID property it throws this exception.Carnage
Ok so I am confused. Does this mean I need to create the same channel on the client machine as the server?Carnage
Yes, both your server, and client need to create the channel.Agreeable
Alan, how do I set the client so that the typeFilterLevel is Full. My Client was created like so. IChannel channel = new TcpClientChannel(); ChannelServices.RegisterChannel(channel, false); (CustomType)Activator.GetObject(typeof(CustomType), "tcp://localhost:9934/CustomType");Carnage
Ok unfortunately what I had done is when I copied over my classes from my application I had applied [Serializable] and MarshalByRefObject to all of them. I just went through and removed all of the MarshalByRefObject inheritance except off of the Orders class and I was able to pass the object successfully.Carnage
C
1

Actually, .NET remoting is an obsolete technology. You should take a look at WCF instead.

Regarding your actual problem: Your probably running your application in a trust-level that is too low.
The Users class should be serializable, but, if it does not contain any methods that should run at the server, it should not derive from MarshalByRefObject

Cortese answered 13/2, 2012 at 21:17 Comment(4)
arguably, remoting still serves a usage for talking between AppDomains in the same process. Just sayin'Sherrilsherrill
I havent looked at WCF yet, and the User class doesnt hold any necessary calls that would need to inherit MarshalByRefObject. I was trying to go the simple route and create a single DLL that could be utilized for the Server and Client Application instead of creating multiple DLL's.Carnage
The practical problem with using an obsolete technology is that there are fewer people who remember it. I just barely remembered that I had seen this error before, but not how to fix it. And I'm old.Hollyanne
Lol ok well, I am young and wanting to embrace the latest and greatest so I should probably look into WCF and figure it out. Also, I dont want to run into major issues with my new app. So thanks for the heads up on this!Carnage

© 2022 - 2024 — McMap. All rights reserved.