Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2010-09-12
4
Medium Priority
?
1,000 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 2000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
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…

670 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