Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

916 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