Search code examples
c#.netvb.netremoting.net-remoting

Issues with Migrating .Net Remoting from Framework 2 to 4


I currently had a .Net Remoting Application running on Framework 2 under IIS. I have to upgrade it to Framework 4 in order to use some new components. I have been able to set everything up and running smootly on Framework 2, but as soon as I change to Framework 4, I get the following exception when I try to call one of the function of my remote object.

The input stream is not a valid binary format. 
The starting contents (in bytes) are: 
53-79-73-74-65-6D-2E-52-75-6E-74-69-6D-65-2E-52-65 ...

This bug is not the real bug, it is caused by the fact that the remote object is throwing an exception, and IIS wrap the exception in XML, which throws the BinaryFormatter off. See this for more info on the bug.

This is very unfortunate because I cannot see what is causing the exception, and having never used any Remoting before, I do not have much ideas as to where to start debugging. It seems the Exception is thrown before even stepping in the code because I do a fair amount of logging and none of it seems to be triggering.

Basically, I'm looking for some clues or pointer from people that encountered similar problems:

  • What could be causing the exception when no code has changed besides Compiling from .Net 2 to .Net 4?
  • How can I get the full Exception message that is returned?

Here is the code that gets the Remote Object

Dim clientProvider As BinaryClientFormatterSinkProvider = New BinaryClientFormatterSinkProvider()
Dim serverProvider As BinaryServerFormatterSinkProvider = New BinaryServerFormatterSinkProvider()
serverProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full

tsChannelName = System.Guid.NewGuid().ToString()

Dim props As IDictionary = New Hashtable()
props("port") = 0
props("name") = tsChannelName
props("typeFilterLevel") = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full
props("secure") = True
props("useDefaultCredentials") = True

Dim Channel As HttpChannel = New HttpChannel(props, clientProvider, serverProvider)

ChannelServices.RegisterChannel(Channel, False)

//Get the object on the Server
Dim rtnComm As I_CMQCComm = Activator.GetObject(GetType(I_CMQCComm), server)

//Knock knock
rtnComm.IsAlive() 'Exception is thrown here

I can provide more information as Needed.


Solution

  • All right!

    First of all, to see the error, it is recommended to change the formatter used, that way it'll be possible to see the entire error.

    Basically, I had a Server Unavailable and IIS would send back HTML which thrown off the Formatter.

    How to see the error:

    Dim clientProvider As SoapClientFormatterSinkProvider = New SoapClientFormatterSinkProvider()
    Dim serverProvider As SoapServerFormatterSinkProvider = New SoapServerFormatterSinkProvider()
    

    Do not forget to change the Web.Config file also

    <channels>
          <channel ref="http" >
             <serverProviders>
                 <formatter ref="soap" />
              </serverProviders>
              <clientProviders>
                 <formatter ref="soap" />
               </clientProviders>
          </channel>
    </channels>
    

    The Server Unavailable was due to an error in IIS. The Error is logged under Application in the Event Viewer (Control Panel -> Administrative Tools -> Event Viewer).

    My error was due to the fact that I had changed the Machine.config file to that IIS wouldn't run under the user ASP_NET. What I didn't know however is that there's a file for each Framework. IIS Simply had no user to start the aspnet_wp.exe process since I had disabled the user ASP_NET.

    Tiny mistakes, hopefully this can help some people debugging their .Net Remoting. It's working perfectly under .Net 4!