Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 4.0 “RemotingException未处理”;试图调用在类型';上声明的方法;System.IFormattable';在暴露';HES.MyProcess'&引用;_C# 4.0_Remoting - Fatal编程技术网

C# 4.0 “RemotingException未处理”;试图调用在类型';上声明的方法;System.IFormattable';在暴露';HES.MyProcess'&引用;

C# 4.0 “RemotingException未处理”;试图调用在类型';上声明的方法;System.IFormattable';在暴露';HES.MyProcess'&引用;,c#-4.0,remoting,C# 4.0,Remoting,我开始使用.NETRemoting,阅读教程和解释,现在在web上看到了至少三个示例,它们看起来都与我的代码相似。我找不到出错的原因。(RemotingException未处理“试图在公开“HES.MyProcess.”的对象上调用在类型“System.IFormattable”上声明的方法”) 我花了六个小时试图解决这个问题,但没有成功地在网上查找,阅读了很多页面。。。 也许你们能帮我一下 MarshalByRefObject派生类如下所示: public class MyProcess :

我开始使用.NETRemoting,阅读教程和解释,现在在web上看到了至少三个示例,它们看起来都与我的代码相似。我找不到出错的原因。(RemotingException未处理“试图在公开“HES.MyProcess.”的对象上调用在类型“System.IFormattable”上声明的方法”) 我花了六个小时试图解决这个问题,但没有成功地在网上查找,阅读了很多页面。。。 也许你们能帮我一下

MarshalByRefObject派生类如下所示:

public class MyProcess : MarshalByRefObject, IMyProcess
{
    //public System.Diagnostics.Process process {get; set;}

    public MyProcess()
    {
        // TODO: Complete member initialization
      //  this.process = Process.GetCurrentProcess();
    }

    public string GetProcessId()
    { Console.WriteLine("I'm on..");
    return "test";
     //  return this.process.Id;
    }
}
我的界面如下所示:

interface IMyProcess
{

     string GetProcessId();

}
namespace HES
{
public class HES_Starter
{
public static void Main(string[] args)
{

        // using TCP protocol
        TcpChannel channel = new TcpChannel(_port);
        //second value is for security settings
        ChannelServices.RegisterChannel(channel, false);
        Console.WriteLine("HES Server here... on PID: " +    Process.GetCurrentProcess().Id);

        //Type, objectUri to access the object remotely, mode
        RemotingConfiguration.RegisterWellKnownServiceType(
          typeof(HES.MyProcess), "HESProcess",
          WellKnownObjectMode.Singleton);


        Console.ReadLine();
}
}
}
我的服务器如下所示:

interface IMyProcess
{

     string GetProcessId();

}
namespace HES
{
public class HES_Starter
{
public static void Main(string[] args)
{

        // using TCP protocol
        TcpChannel channel = new TcpChannel(_port);
        //second value is for security settings
        ChannelServices.RegisterChannel(channel, false);
        Console.WriteLine("HES Server here... on PID: " +    Process.GetCurrentProcess().Id);

        //Type, objectUri to access the object remotely, mode
        RemotingConfiguration.RegisterWellKnownServiceType(
          typeof(HES.MyProcess), "HESProcess",
          WellKnownObjectMode.Singleton);


        Console.ReadLine();
}
}
}
最后,我的客户是这样的:

namespace Service_Provider
{
public class Program
{
public static void Main(string[] args)
{

        TcpChannel channel = new TcpChannel();
        //second value is for security settings
        ChannelServices.RegisterChannel(channel, false);

        Console.WriteLine("HES Client here...");

        IMyProcess remoteProcess = (IMyProcess)Activator.GetObject(
                typeof(IMyProcess), "tcp://localhost:8050/HESProcess");


        Console.WriteLine(remoteProcess);
        Console.WriteLine(remoteProcess.GetProcessId());
        Console.ReadLine();
    }
}
}
有人知道我做错了什么吗? 我的意思是,从异常中,我可以看到客户机知道该对象是“HES”命名空间中的远程对象。在调试中,我可以看到

remoteProcess = {System.Runtime.Remoting.Proxies.__TransparentProxy} 
是一个代理。。。
我不知道我做错了什么。

您是否尝试过取出
控制台.WriteLine(remoteProcess)行?我猜这就是问题的根源。嗯,是的,谢谢,我不记得我为什么把它放在。。。Console.WriteLine(远程进程);正在查找另一个错误…现在我遇到了此错误:无法加载类型“Service Provider.IProcess,Service Provider,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null”。我认为这就是我在代码中使用console.writeline的原因。你知道这个错误是什么意思吗?解决了!感谢@Jon!剩下的问题在这里解决了:你们想让我研究一下为什么这条线会导致那个问题,还是它现在对你们来说不是特别相关?