serialize a file which is stored in a memorystream object

G

Guest

Hi,

I am using dotnet remoting with a binarry formatter.

I have a property that returns a memorystream that has had a file loaded
into it.

When I try to access this property though I get an error regarding "the
proxy has no channel sink....[]...or no suitable Client channel to talk to
the server."

I have investigated a bit and have come to the conclusion that the
memorystream object can itself be serialized with a binary formatter, but
when it is deserialized it throws an exception stating that

"End of Stream encountered before parsing was completed."

Can anybody suggest a way around this, or indeed a different way than the
memorystream to pass file data trhough remoting boundaries using the
binaryformatter?

In case its of use, this is the code I used to try out my
serialize/deserialize test...

// SEEMS TO SERIALIZE ok BUT THROWS AN ERROR ON DESIERIALIZE!!!!
BinaryFormatter objSerializer = new BinaryFormatter();
BinaryFormatter objDeserializer = new BinaryFormatter();
FileStream fst = File.OpenRead(Path.GetFullPath(file));
System.IO.MemoryStream objStream = GetMemoryStream(fst);
System.IO.MemoryStream objSerializedStream = new System.IO.MemoryStream();
objSerializer.Serialize(objSerializedStream, objStream);
System.IO.MemoryStream objReturnStream = new System.IO.MemoryStream();
try
{
//objReturnStream =
(MemoryStream)(objDeserializer.Deserialize(objSerializedStream));
object objDeserialisedFile =
objDeserializer.Deserialize(objSerializedStream);
}
catch(Exception ex)
{
MessageBox.Show("Exception: " + ex.Message);
}
 
G

Guest

Hi Phil

I think you might have to reset your memory stream back to the start before
deserializing it.

objSerializedStream.Seek(0, SeekOrigin.Begin);

It is already at the end of the stream when it attempts to deserialize it.
Resetting it to the start might fix your problem.

HTH

Ged
 
G

Guest

Hi Ged,

Thanks for that, that worked for that test and it showed that the memory
stream can indeed be serialised and deserialised by the binary formatter.

SO does anybody have any idea why my remoting is failing on the property
that exposes a MemoryStream object?

I can set the property itself to a memory stream object on the client, but
in the next line when I try to get the data out of the object I get this
error:

Error
====
This remoting proxy has no channel sink which means either the server has no
registered server channels that are listening, or this application has no
suitable client channel to talk to the server.

StackTrace
===========
Server stack trace:
at
System.Runtime.Remoting.Proxies.RemotingProxy.InternalInvoke(IMethodCallMessage reqMcmMsg, Boolean useDispatchMessage, Int32 callType)
at System.Runtime.Remoting.Proxies.RemotingProxy.Invoke(IMessage reqMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&
msgData, Int32 type)
at System.IO.Stream.Write(Byte[] buffer, Int32 offset, Int32 count)
at System.IO.MemoryStream.WriteTo(Stream stream)
at
System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(MethodBase
mb, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext,
Object[]& outArgs)\r\n at
System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage
msg, Int32 methodPtr, Boolean fExecuteInContext)\n\nException 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 System.IO.MemoryStream.WriteTo(Stream stream)
at ConsoleApplication1.Class1.SaveMemoryStream(MemoryStream ms, String
FileName) in
c:\\hexagon\\hexagon.mycontainer\\consoleapplication\\class1.cs:line 160
at ConsoleApplication1.Class1.Main(String[] args) in
c:\\hexagon\\hexagon.mycontainer\\consoleapplication\\class1.cs:line
85" string

--
Regards,

Phil Johnson (MCAD)


Ged said:
Hi Phil

I think you might have to reset your memory stream back to the start before
deserializing it.

objSerializedStream.Seek(0, SeekOrigin.Begin);

It is already at the end of the stream when it attempts to deserialize it.
Resetting it to the start might fix your problem.

HTH

Ged


Phil Johnson said:
Hi,

I am using dotnet remoting with a binarry formatter.

I have a property that returns a memorystream that has had a file loaded
into it.

When I try to access this property though I get an error regarding "the
proxy has no channel sink....[]...or no suitable Client channel to talk to
the server."

I have investigated a bit and have come to the conclusion that the
memorystream object can itself be serialized with a binary formatter, but
when it is deserialized it throws an exception stating that

"End of Stream encountered before parsing was completed."

Can anybody suggest a way around this, or indeed a different way than the
memorystream to pass file data trhough remoting boundaries using the
binaryformatter?

In case its of use, this is the code I used to try out my
serialize/deserialize test...

// SEEMS TO SERIALIZE ok BUT THROWS AN ERROR ON DESIERIALIZE!!!!
BinaryFormatter objSerializer = new BinaryFormatter();
BinaryFormatter objDeserializer = new BinaryFormatter();
FileStream fst = File.OpenRead(Path.GetFullPath(file));
System.IO.MemoryStream objStream = GetMemoryStream(fst);
System.IO.MemoryStream objSerializedStream = new System.IO.MemoryStream();
objSerializer.Serialize(objSerializedStream, objStream);
System.IO.MemoryStream objReturnStream = new System.IO.MemoryStream();
try
{
//objReturnStream =
(MemoryStream)(objDeserializer.Deserialize(objSerializedStream));
object objDeserialisedFile =
objDeserializer.Deserialize(objSerializedStream);
}
catch(Exception ex)
{
MessageBox.Show("Exception: " + ex.Message);
}
 
G

Guest

SOLUTION

The issue turned out to be with a method that accepted a memory stream.....
I found some good advice here and implemented an overloaded method that took
a byte array parameter instead...

http://www.dotnet247.com/247reference/msgs/26/133439.aspx

--
Regards,

Phil Johnson (MCAD)


Phil Johnson said:
Hi Ged,

Thanks for that, that worked for that test and it showed that the memory
stream can indeed be serialised and deserialised by the binary formatter.

SO does anybody have any idea why my remoting is failing on the property
that exposes a MemoryStream object?

I can set the property itself to a memory stream object on the client, but
in the next line when I try to get the data out of the object I get this
error:

Error
====
This remoting proxy has no channel sink which means either the server has no
registered server channels that are listening, or this application has no
suitable client channel to talk to the server.

StackTrace
===========
Server stack trace:
at
System.Runtime.Remoting.Proxies.RemotingProxy.InternalInvoke(IMethodCallMessage reqMcmMsg, Boolean useDispatchMessage, Int32 callType)
at System.Runtime.Remoting.Proxies.RemotingProxy.Invoke(IMessage reqMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&
msgData, Int32 type)
at System.IO.Stream.Write(Byte[] buffer, Int32 offset, Int32 count)
at System.IO.MemoryStream.WriteTo(Stream stream)
at
System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(MethodBase
mb, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext,
Object[]& outArgs)\r\n at
System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage
msg, Int32 methodPtr, Boolean fExecuteInContext)\n\nException 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 System.IO.MemoryStream.WriteTo(Stream stream)
at ConsoleApplication1.Class1.SaveMemoryStream(MemoryStream ms, String
FileName) in
c:\\hexagon\\hexagon.mycontainer\\consoleapplication\\class1.cs:line 160
at ConsoleApplication1.Class1.Main(String[] args) in
c:\\hexagon\\hexagon.mycontainer\\consoleapplication\\class1.cs:line
85" string

--
Regards,

Phil Johnson (MCAD)


Ged said:
Hi Phil

I think you might have to reset your memory stream back to the start before
deserializing it.

objSerializedStream.Seek(0, SeekOrigin.Begin);

It is already at the end of the stream when it attempts to deserialize it.
Resetting it to the start might fix your problem.

HTH

Ged


Phil Johnson said:
Hi,

I am using dotnet remoting with a binarry formatter.

I have a property that returns a memorystream that has had a file loaded
into it.

When I try to access this property though I get an error regarding "the
proxy has no channel sink....[]...or no suitable Client channel to talk to
the server."

I have investigated a bit and have come to the conclusion that the
memorystream object can itself be serialized with a binary formatter, but
when it is deserialized it throws an exception stating that

"End of Stream encountered before parsing was completed."

Can anybody suggest a way around this, or indeed a different way than the
memorystream to pass file data trhough remoting boundaries using the
binaryformatter?

In case its of use, this is the code I used to try out my
serialize/deserialize test...

// SEEMS TO SERIALIZE ok BUT THROWS AN ERROR ON DESIERIALIZE!!!!
BinaryFormatter objSerializer = new BinaryFormatter();
BinaryFormatter objDeserializer = new BinaryFormatter();
FileStream fst = File.OpenRead(Path.GetFullPath(file));
System.IO.MemoryStream objStream = GetMemoryStream(fst);
System.IO.MemoryStream objSerializedStream = new System.IO.MemoryStream();
objSerializer.Serialize(objSerializedStream, objStream);
System.IO.MemoryStream objReturnStream = new System.IO.MemoryStream();
try
{
//objReturnStream =
(MemoryStream)(objDeserializer.Deserialize(objSerializedStream));
object objDeserialisedFile =
objDeserializer.Deserialize(objSerializedStream);
}
catch(Exception ex)
{
MessageBox.Show("Exception: " + ex.Message);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top