473,320 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Serialization of System::Int32^ problem

I'm developing a client/server application (in VS2005 managed C++) which
makes use of .Net remoting. A simplified solution which demonstrates the
problem I'm having can be found at:

http://www.nmt.edu/~elessar/RemotingTest.tar.bz2
http://www.nmt.edu/~elessar/RemotingTest.zip

Uncommenting Server.cpp line 67 causes the problem. Removing it fixes the
problem. The server listens on port 1357, and the client connects to
localhost:1357.

I've defined the following classes in an assembly referenced by both the
client and the server:

[System::Serializable]
public ref class ExchangeObject
{
public:
ExchangeObject::ExchangeObject();
System::Object ^myob;
System::Int32 ^myint;
};

public delegate void ObjectHandler (General::ExchangeObject ^object);

public interface class IRemoteClient
{
public:
void Object_For_Client (General::ExchangeObject ^exch_ob);
};

public interface class IRemoteServer
{
public:
int AddClient (General::IRemoteClient ^client);
void RemoveClient (int client_id);
void Object_For_Device (General::ExchangeObject ^exch_ob);
};

Obviously, the client implements IRemoteClient, and the server implements
IRemoteServer. Both are MarshalByRef. When the server starts, it creates an
instance of the server class, then publishes it with

System::Runtime::Remoting::RemotingServices::Marsh al

The client creates an instance of the client class, gets a reference to the
remote server, then passes a reference to the client object to the server,
using the AddClient() method. Once the connection is established, the client
and server can exchange messages by calling the Object_For_Client() and
Object_For_Server() methods. This is all working just fine.

The problem arises when I put a value in the myint field of the
ExchangeObject. As long as the field is a nullptr, everything is fine. If I
put a reference to a System::Int32 in myob, things are also fine. However,
if I initialize the myint field with something like:

exch_ob->myint = gcnew System::Int32(42);

then the object will no longer properly serialize. When the server tries to
call Object_For_Client with the object, it throws a

System.Runtime.Serialization.SerializationExceptio n

Binary stream '42' does not contain a valid BinaryHeader. Possible causes
are invalid stream or object version change between serialization and
deserialization.

Suspiciously, the referenced binary stream is the same number as the integer
I was trying to send, and it changes to match when I change the integer. At
this point, I'm suspecting that this is a bug in the compiler or framework,
but I'm hoping that it's just something I've done wrong, so I can fix it.
Any suggested fixes or workarounds would be greatly appreciated.

Thanks for any help and suggestions,
-Thomee Wright-
Jun 23 '06 #1
3 1486
One clarification. I'm using a BinaryFormatter on a TcpChannel

-Thomee-
Jun 23 '06 #2
Hello Thomee,

Thank you for the posting. I have download your sample and studying on it.
I will update you as soon as possible. If you also have any progress,
please let us know.

Thanks,

Luke Zhang
Microsoft Online Community Lead

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Jun 26 '06 #3
With you sample, I also found the same problem. I agree with you that it is
more like a bug: I searched in our database and found similiar issue
reported as bugs. If the issue really impact your development, I suggest
you may contact our PSS to request a fix or work around. To submit a
support incident, you may go to

http://msdn.microsoft.com/subscriptions/

And click Support Incidents.

Thanks,

Luke Zhang
Microsoft Online Community Lead

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Jun 27 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Andrea | last post by:
I was trying to deserialize my xml file (I enclose it below ) into a class. So I generated an xsd file given my xml using the MS xsd tool; then I generated the corresponsing C# class (using the MS...
1
by: Hifni Shahzard | last post by:
Hi, I got a stored procedure, where it returns a value. But if I execute it. It gives an error as "Invalid cast from System.Int32 to System.Byte.". To make clear how do I execute this, below I'm...
2
by: Simon Harris | last post by:
I have created a web service, which when I call in my browser presents the text form etc. When I click the button, I get this error: System.ArgumentException: Cannot convert to System.Int32....
3
by: Søren M. Olesen | last post by:
Hi How do I dynamically create a type of System.Int32 with the value 123?? I've tried the following: Dim keyci As ConstructorInfo = Type.GetType("System.Int32").GetConstructor(New Type()...
2
by: Carlo, MCP | last post by:
Hello, I'm troubling from months with a serious serialization problem that I'm not able to solve. I try to describe as simply as I can. 1) I have a class tha does something with colors. All...
7
by: Joe | last post by:
I've tracked the performance issue down to a single class. This class derives from CollectionBase and stores a basic value type such as string, int, double, etc... I also store the type itself...
0
by: Kiran A K | last post by:
Hi, When I try to return an object of type "System.Diagnostics.PerformanceCounter" from a web method i got the following error: Cannot serialize member System.ComponentModel.Component.Site of...
3
by: keithb | last post by:
What could be causing this? this code: String Com = ""; if (Com != (String)rw.ItemArray) fails at runtime with the error message: Unable to cast object of type 'System.Int32' to type...
1
by: northerntechie | last post by:
Ok, I don't normally post (I would rather rummage around in the thoughts and frustrations of others) but this one has got me stumped. I am using MS VB 2005 Express and I am using a COM object...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.