Error passing a large variable as a parameter to a remote method

When passing a large byte array as a parameter to a remote method, I get the following error:

System.Runtime.Serialization.SerializationException: The input stream is not a valid binary format. The starting contents (in bytes) are: 53-79-73-74-65-6D-2E-57-65-62-2E-48-74-74-70-45-78 ... Server stack trace: at System.Runtime.Serialization.Formatters.Binary.SerializationHeaderRecord.Read(__BinaryParser input)... etc.

The largest byte array I can successfully pass across the wire is 4,193,890 elements in size, as soon as I go to 4,193,891 it bombs out with the above exception.

I am running the .NET Framework 2.0 Beta 2. The server is a singleton object hosted inside IIS 6.0 running on Windows Server 2003, using the Http channel with the Binary formatter. The client is a Windows Forms application running on Windows XP.

The same error occurs if I pass a large string as a parameter instead of a byte array, so the problem seems to be with the size of the parameter instead of the type.

Any chance this should should be reported to Microsoft, or am I just doing something silly here... thanks for any help! :-)

[1133 byte] By [dsmithwv] at [2008-2-14]
# 1
How long is the request taking before it fails?

What connection timeout settings do you have set?

douglasp at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Remoting and Runtime Serialization...
# 2
It takes less than one second -- I've just tried it with both the client and server on the same machine, so network latency is not an issue. The connection timeout has not been changed, so it is the default (which I believe is 15 seconds). I'm using a Packet Size of 4096 (which is less than the default of 8192) but I'm not sure why, I think I simply used a wizard in visual studio to generate the connection string.

Here's my workaround (though it lacks a bit from a performance perspective) -- I instantiate a MarshalByRefObject on the server which hosts an ArrayList. Then I feed the byte array to the remote object in chunks. The object is then passed to my remote method which knows how to reconstruct the original byte array from the ArrayList.

I can't seem to find any information on this exception ("The input stream is not a valid binary format"). A google search turns up nothing, and neither does MSDN.

dsmithwv at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Remoting and Runtime Serialization...
# 3

I've also discovered that this error also occurs when attempting to send a MarshalByRefObject to a method of a remote object. I definitely would not expect a SerializationException to occur in this case, since a MarshalByRefObject should not be serialized (and I have not marked the class as [Serializable] either).

dsmithwv at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Remoting and Runtime Serialization...
# 4
I've created some sample code that demonstrates the problem. The "Invalid Binary Format" exception will occur on any call to the remote object. There are several test methods, including one that sends a large byte array (the original problem I ran into). I am getting the error even on a method that takes no parameters and returns null. So aparantly the scope of the problem is larger than I realized.

I can send a copy of the VS2005 solution I used to replicate the problem. Please let me know if you would like a copy.

Thanks for any help :-)

dsmithwv at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Remoting and Runtime Serialization...
# 5

I've discovered that the the actual exception was be obfuscated by the SerializationException (the old problem of attempting to deserialize XML text as binary data)... in any case the actual exception is this:

IOException: An established connection was aborted by the software in your host machine

I'm not sure what software would be aborting the connection. So there's something else going on here.

dsmithwv at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Remoting and Runtime Serialization...
# 6
4193891/1024 is approximately 4096

4096 is the default maxRequestLength for an ASP.NET request to a server. this is the most probable cause...

you can change this behavior in your config file.

<configuration>
<system.web>
<httpRuntime>

<httpRuntime
useFullyQualifiedRedirectUrl
="true|false"
enable = "true|false"
idleTime =
"minutes"
maxRequestLength
="size in kbytes"
executionTimeout
="seconds"
minFreeThreads="
number of threads"
minFreeLocalRequestFreeThreads=
"number of threads"
appRequestQueueLimit=
"number of requests"
enableVersionHeader=
"true/false"/>
see http://whidbey.msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_aspnetgenref/html/e9b81350-8aaf-47cc-9843-5f7d0c59f369.asp

also,
Large Data Strategies
http://whidbey.msdn.microsoft.com/library/default.asp?url=/library/en-us/dnservice/html/service11072001.asp

Uploading Files Using the File Field Control
http://whidbey.msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/aspnet-fileupload.asp

a search on maxRequestLength yields a handful of others.

stand__sure at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Remoting and Runtime Serialization...
# 7
Thanks so much, that's exactly what I needed!
dsmithwv at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Remoting and Runtime Serialization...
# 8
my pleasure.
stand__sure at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Remoting and Runtime Serialization...
# 9
Just as an FYI, this same error message will be produced if you forget to include the namespace of the class when specifying the type.

Stupid me did this (the class was wrapped in a namespace) and couldn't work out why I was getting this.

The joys of programming!

BrendanGreen at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Remoting and Runtime Serialization...
# 10
dsmithwv wrote:
I've created some sample code that demonstrates the problem. The "Invalid Binary Format" exception will occur on any call to the remote object. There are several test methods, including one that sends a large byte array (the original problem I ran into). I am getting the error even on a method that takes no parameters and returns null. So aparantly the scope of the problem is larger than I realized.

I can send a copy of the VS2005 solution I used to replicate the problem. Please let me know if you would like a copy.

Thanks for any help :-)


Can you show me an example with this problem is fixed? Thank you.
cnSoftware at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Remoting and Runtime Serialization...
# 11
dsmithwv wrote:
I've created some sample code that demonstrates the problem. The "Invalid Binary Format" exception will occur on any call to the remote object. There are several test methods, including one that sends a large byte array (the original problem I ran into). I am getting the error even on a method that takes no parameters and returns null. So aparantly the scope of the problem is larger than I realized.

I can send a copy of the VS2005 solution I used to replicate the problem. Please let me know if you would like a copy.

Thanks for any help :-)

I so much need your help here.

I have a simple application ... and its going to get big :) if i figure out the .NET remoting part.
It just wont work.

Its based on configuration files. I use VS 2005 - .NET 2.0 - IIS 6.0 to host the remoting objects and a simple Form GUI to test. I use binary format.

thats the code :

web.config - server :

<system.runtime.remoting>
<application>
<service>
<wellknown mode="SingleCall" objectUri="Mail.rem" type="RemotingServer.MailManager, RemotingServer" />
</service>
<channels>
<channel ref="http">
<serverProviders>
<formatter ref="binary" typeFilterLevel="Full" />
</serverProviders>
</channel>
</channels>
</application>
</system.runtime.remoting>


client - app.config

<system.runtime.remoting>
<application name="clientUI">
<client url="http://xxxxxxxx:8000/RemoteIIS/Mail.rem" type="RemotingServer.MailManager, RemotingServer">
</client>
<channels>
<channel ref="http">
<clientProviders>
<formatter ref="binary"/>
</clientProviders>
<serverProviders>
<formatter ref="binary" typeFilterLevel="Full"/>
</serverProviders>
</channel>
</channels>
</application>

and thats is the code of my client (an onlick handler) :

Try

Dim configFilePath As String = System.IO.Path.Combine(System.Environment.CurrentDirectory, "ClientUI.exe.config")
RemotingConfiguration.Configure(configFilePath, False)

'1.
'Dim service As RemotingServer.Mailmanager = New RemotingServer.Mailmanager()
'2.
'Dim service As RemotingServer.Mailmanager = CType(Activator.GetObject(GetType(RemotingServer.Mailmanager), "http://pdsintranet:8000/RemoteIIS/Mail.rem"), RemotingServer.Mailmanager)
'3.
Dim o As Object = RemotingServices.Connect(GetType(RemotingServer.Mailmanager), "http://pdsintranet:8000/RemoteIIS/Mail.rem")
Dim service As RemotingServer.Mailmanager = CType(o, RemotingServer.Mailmanager)

Debug.Print(RemotingServices.IsTransparentProxy(service))
Debug.Print(service.getCompName())

'Me.Mail1.Merge(service.GetEmails())

Catch eX As Exception

Debug.Write(eX.StackTrace())

End Try

if i try to get the Mailmanager object by the 1st way : i get the local copy!!!
with the 2nd and 3rd ways i get the error you discuss on this thread :
Invalid Binary Format etc..

I would really appreciate your help.

Thanks in advance


stratos13 at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Remoting and Runtime Serialization...
# 12
Saved me a full night's frustration. Thanks dude.
sashisme at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Remoting and Runtime Serialization...

.NET Development

Site Classified