Solved

Value cannot be null. Parameter name: type in .NET remoting

Posted on 2010-09-12
4
985 Views
Last Modified: 2012-05-10
I have added the following sample code from Microsoft website:

Server Code

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

namespace RemoteServer
{
    class Program
    {
        static void Main(string[] args)
        {
            TcpChannel chan = new TcpChannel(8085);
            ChannelServices.RegisterChannel(chan, false);
            RemotingConfiguration.RegisterWellKnownServiceType(Type.GetType("RemoteObject.HelloServer,object"), "SayHello", WellKnownObjectMode.SingleCall);
            //RemotingConfiguration.RegisterWellKnownServiceType(Type.GetType("RemotableOPCObject.RemotableOPCObject, RemotableOPCObject"), "RemoteTcpTest", WellKnownObjectMode.SingleCall);
            System.Console.WriteLine("Hit <enter> to exit...");
            System.Console.ReadLine();
        }
    }
}

Object Code

using System;
using System.Collections.Generic;
using System.Text;

namespace RemoteObject
{
    public class HelloServer : MarshalByRefObject
    {
        public HelloServer()
        {
            Console.WriteLine("HelloServer activated");
        }

        public String HelloMethod(String name)
        {
            Console.WriteLine("Hello.HelloMethod : {0}", name);
            return "Hi there " + name;
        }
    }
}

Client Code

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

namespace RemoteClient
{
    class Program
    {
        static void Main(string[] args)
        {
            //TcpChannel chan = new TcpChannel();
            //ChannelServices.RegisterChannel(chan, false);
            RemoteObject.HelloServer obj = (RemoteObject.HelloServer)Activator.GetObject(typeof(RemoteObject.HelloServer), "tcp://localhost:8085/SayHello");
            //RemotableOPCObject.RemotableOPCObject obj = (RemotableOPCObject.RemotableOPCObject)Activator.GetObject(typeof(RemotableOPCObject.RemotableOPCObject), "tcp://localhost:8085/RemoteTest");
            if (obj == null)
                System.Console.WriteLine("Could not locate server");
            else
                //Console.WriteLine(obj.ReturnHelloMessage());
                Console.WriteLine(obj.HelloMethod("Caveman"));
        }
    }
}


When I try to run the server, it throws the following Exception at the following line......
            RemotingConfiguration.RegisterWellKnownServiceType(Type.GetType("RemoteObject.HelloServer,object"), "SayHello", WellKnownObjectMode.SingleCall);

I have attached the exception image below.

I can't figure out what's going on? If you have any idea, please share....Thanks
1.bmp
0
Comment
Question by:YetAnotherCoder
  • 2
4 Comments
 
LVL 65

Accepted Solution

by:
rockiroads earned 500 total points
ID: 33659201
whats the difference between using Type.GetType and typeof

if u tried typeof does that make a difference?

 RemotingConfiguration.RegisterWellKnownServiceType(typeof("RemoteObject.HelloServer,object"), "SayHello", WellKnownObjectMode.SingleCall);

I think the main difference between the two might be one requires an instance
0
 
LVL 14

Expert Comment

by:existenz2
ID: 33659985
It should be the following, without the ",object"

Also what rockiroads says is true, it's better to use typeof(), that saves you typing a string (and making mistakes in the naming).
RemotingConfiguration.RegisterWellKnownServiceType(Type.GetType("RemoteObject.HelloServer"), "SayHello", WellKnownObjectMode.SingleCall);

Open in new window

0
 

Author Comment

by:YetAnotherCoder
ID: 33668242
Actually I figured out the solution right after I posted but didn't update quickly. The solution is to use typeof(namespace.classname). BUT it has worked in the past with Type.GetType("Namespace.ClassName, Namespace.ClassName). I don't know what made this not to work anymore all of a sudden. But thanks to rockiroads.......
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 33668297
probably what not made it work was it couldnt find an instance, thats about the one major difference I found between the two.
still you cracked it so thats the main thing and thanks for the points :)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question