Mike Christensen
Mike Christensen

Reputation: 91628

.NET Remoting works from a web app, but not from within a WCF host

This one has had me stumped for a few hours now, and I have absolutely no ideas. I have the following remoting code:

private static IRolesAndResourcesManager InternalConnect(string host, string operatorName)
{
    string url = string.Format("tcp://{0}:{1}/IProxyFactory", host, ServicePort);
    object o = Activator.GetObject(typeof (IProxyFactory), url);
    IProxyFactory factory = (IProxyFactory) o;

    return factory.CreateRolesAndResourcesManager(operatorName);
}

When this is called from within our web site, it works fine. However, we also link to this same DLL from a WCF hosted service (basically, a console app). When I call the same method from within that process, I get an exception on the follow line:

return factory.CreateRolesAndResourcesManager(operatorName); // <-- Exception!

The exception is:

System.InvalidCastException: Return argument has an invalid type.\r\n at System.Runtime.Remoting.Proxies.RealProxy.ValidateReturnArg(Object arg, Type paramType)

Everything I've found so far says there's some sort of DLL mismatch; as if the WCF process was linked to an old version of the DLL. However, I've tried deleting every binary, cleaning, rebuilding. Heck, I've ever tried deleting the entire enlistment and checking out everything from Subversion again. I can also verify the CreateRolesAndResourcesManager method runs on the Remoting host side and returns valid data.

Is there anything else that can cause this sort of exception, besides a DLL mismatch? Is there any way to get more information on this error?

Update:

Definitely not a CLR version mismatch. All three processes (IIS Express, Remoting Host, WCF process) have the following Environment.Version:

{4.0.30319.18444}
    Build: 30319
    Major: 4
    MajorRevision: 0
    Minor: 0
    MinorRevision: 18444
    Revision: 18444

I've also ran Visual Studio as well as all processes as Admin to see if there's a security issue, but that doesn't fix the issue either.

Upvotes: 0

Views: 628

Answers (1)

Erik Funkenbusch
Erik Funkenbusch

Reputation: 93444

This question and answer:

System.InvalidCastException when creating a client activated object using an older version of an interface defined in a strong named assembly

Suggests that if the version of the .NET CLR used in the server and client are different, this error can occur, and that with .NET Remoting they both have to be the same version of the CLR. I'm not certain if that is the case, but you might want to check....

Upvotes: 1

Related Questions