Solved

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

Posted on 2010-09-12
4
995 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

622 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