Solved

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

Posted on 2010-09-12
4
977 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

757 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now