locked
Proxy failed to create remote object on the server

    Question

  • Hi,

    I am using .net remoting for inter-process communication between two processes on the same machine

    1.   The first process is one of the Office application: Ecxel /   Word /   PP

    2.   The other process is another application that interacts with one of the above. For that it needs office application object. For example: Excel

    The solution is comprised with 3 projects:

    Project #1:

    The remote object is a simple Called RemoteOfficeApplication – that simply wraps the required application object (Word / Excel / PP).

     

    Project #2:

    The Server is a simple Office add-in, written with a Visual Studio Extensibility -> Shared project.

    This add-in is instantiated whenever Excel is lunched.

    This project reference project #1.

    Code:

     var channel = new TcpChannel (5003);     
    
     ChannelServices.RegisterChannel(channel,true );
    
    RemotingConfiguration.RegisterWellKnownServiceType(
    
       typeof (RemoteOfficeApplication.RemoteOfficeApplication ),
    “AppObj”,
    WellKnownObjectMode .Singleton);
     

    Project #3:

    The Client is the process that requires the application object. This project also reference project #1.

    Code:

     

    //Get Remote object proxy
    object remoteAppObject =
        Activator.GetObject(typeof(RemoteOfficeApplication.RemoteOfficeApplication),
                        “tcp://localhost:5003/AppObj" );
    //Cast the proxy
    var remoteAppObject1
       = remoteAppObject as RemoteOfficeApplication.RemoteOfficeApplication ;
    
     
     //Create Real remote app object from proxy and get application object from it
     object applicationObject = remoteAppObject1.GetOfficeApplication();
    
    
    

    The problem:

    When the client execute GetOfficeApplication() .NET remoting tries instantiate the remote object on the server but somehow it cant find RemoteOfficeApplication.dll

    The dll resides on the same directory as the add-in (i.e. server).

    I also checked with Fusion Assembly Log Viewer and saw that .NET looks for the dll in that directory – but it doesn’t find it.

    The exception is:

    FileNotFoundException(Could not load file or assembly 'RemoteOfficeApplication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.)     

    Help Please?

    tx

    Oren

    Tuesday, August 10, 2010 7:13 PM

All replies

  • Just to be clear, is the FileNotFoundException the server side? I can't quite imagine why that would be happening if it has already run the code

    RemotingConfiguration.RegisterWellKnownServiceType(

       typeof (RemoteOfficeApplication.RemoteOfficeApplication ),<br/>
       “AppObj”, <br/>
       WellKnownObjectMode .Singleton);<br/>

    Could you add some call stack information?

    Tim

    Thursday, August 12, 2010 7:04 AM
  • Hi,

    Yes - the exception comes from the server - when it actually try instantiate the object

    I understand what you say RegisterWellKnownServiceType - but this is actually the first time I use remoting so it always possible I miss something...

    Tx

    Oren

    This is the call stack:

    FileNotFoundException(Could not load file or assembly 'RemoteOfficeApplication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.)    
          
     Server stack trace:     
     at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean  throwOnFileNotFound, Boolean forIntrospection)    
     at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)    
     at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)    
     at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)    
     at System.Reflection.Assembly.Load(String assemblyString)    
     at System.Runtime.Remoting.RemotingConfigHandler.RemotingConfigInfo.LoadType(String typeName, String assemblyName)    
     at System.Runtime.Remoting.RemotingConfigHandler.RemotingConfigInfo.GetServerTypeForUri(String URI)    
     at System.Runtime.Remoting.RemotingConfigHandler.GetServerTypeForUri(String URI)    
     at System.Runtime.Remoting.RemotingServices.GetServerTypeForUri(String URI)    
     at System.Runtime.Remoting.Channels.BinaryServerFormatterSink.ProcessMessage(IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, IMessage& responseMsg, ITransportHeaders& responseHeaders, Stream& responseStream)    
         
    Exception rethrown at [0]:     
     at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)    
     at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)    
     at RemoteOfficeApplication.RemoteOfficeApplication.get_OfficeApplication()    
     at CovertixAutoTests.OfficeTesters.OfficeTester.SetAppObj(Process appProcess) in

     


    Thursday, August 12, 2010 4:20 PM
  • Well, this has got me confused. It doesn't seem to make sense that it can fail to load exactly the same type as you registered.

     var channel = new TcpChannel (5003);   
    
     ChannelServices.RegisterChannel(channel,true );
    
    RemotingConfiguration.RegisterWellKnownServiceType(
    
      typeof (RemoteOfficeApplication.RemoteOfficeApplication ),<br/>
      “AppObj”, <br/>
      WellKnownObjectMode .Singleton);<br/>
     
    

    Unless, that is, it is one of those type T != type T issues you can get from either mismatched assembly versions, or using the LoadFrom context. Any chance either of those explains it?

    If you own the server code, one other thing you could maybe try to investigate what is really happening - create a custom SerializationBinder, so you can do the type load yourself, and debug all around it...

    Tim

    Friday, August 13, 2010 4:36 AM
  • Hi,

    I own all the code so I did some more checkings

     

    I do not think its a type mismatch as you have suggested - because

    1. All code is mine and I reference it to the same physical dll (client and server)

    2. I debug the server and when Loading assembly with

     Assembly.GetAssembly(typeof(RemoteOfficeApplication.RemoteOfficeApplication));
    

    Loaded assembly has the same attributes as the exception indicates (Version, Culture,PublicTokenKey)

     

    I tried to instantiate within the server RemoteOfficeApplication in three different ways:

    1. By New keyword - alll good

    2. LoadAssembly - giving the short name of the assembly (RemoteOfficeApplication.dll) - FileNotFound

    3. LoadAssembly - giving the full name of the assembly (c:\RemoteOfficeApplication.dll) - all good

    The question is why #2 is not working. The project (RemoteOfficeApplication) is ComVisible so that the server which is a Office Addin (i.e. Com Object) will "see it"

    Does this info gives you any idea?

     

    Tx

     

    Oren

    Friday, August 13, 2010 12:46 PM
  • How about LoadAssembly giving the 'fullname' of the assembly as in the error message? RemoteOfficeApplication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

    "Could not load file or assembly 'RemoteOfficeApplication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'"?

    Tim

    Friday, August 13, 2010 3:27 PM
  • Worked.

    Maybe it has something with strong name or signing the assembly? Maybe GAC?

    Friday, August 13, 2010 10:44 PM