473,221 Members | 1,589 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,221 software developers and data experts.

serialize a file which is stored in a memorystream object

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(objSeri alizedStream));
object objDeserialisedFile =
objDeserializer.Deserialize(objSerializedStream);
}
catch(Exception ex)
{
MessageBox.Show("Exception: " + ex.Message);
}
--
Regards,

Phil Johnson (MCAD)
Aug 17 '07 #1
3 5485
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" <Ph*********@discussions.microsoft.comwrote in message
news:E1**********************************@microsof t.com...
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(objSeri alizedStream));
object objDeserialisedFile =
objDeserializer.Deserialize(objSerializedStream);
}
catch(Exception ex)
{
MessageBox.Show("Exception: " + ex.Message);
}
--
Regards,

Phil Johnson (MCAD)
Aug 17 '07 #2
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.Inte rnalInvoke(IMethodCallMessage reqMcmMsg, Boolean useDispatchMessage, Int32 callType)
at System.Runtime.Remoting.Proxies.RemotingProxy.Invo ke(IMessage reqMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateI nvoke(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.HandleRe turnMessage(IMessage
reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateI nvoke(MessageData&
msgData, Int32 type)
at System.IO.MemoryStream.WriteTo(Stream stream)
at ConsoleApplication1.Class1.SaveMemoryStream(Memory Stream ms, String
FileName) in
c:\\hexagon\\hexagon.mycontainer\\consoleapplicati on\\class1.cs:line 160
at ConsoleApplication1.Class1.Main(String[] args) in
c:\\hexagon\\hexagon.mycontainer\\consoleapplicati on\\class1.cs:line
85" string

--
Regards,

Phil Johnson (MCAD)
"Ged" wrote:
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" <Ph*********@discussions.microsoft.comwrote in message
news:E1**********************************@microsof t.com...
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(objSeri alizedStream));
object objDeserialisedFile =
objDeserializer.Deserialize(objSerializedStream);
}
catch(Exception ex)
{
MessageBox.Show("Exception: " + ex.Message);
}
--
Regards,

Phil Johnson (MCAD)

Aug 17 '07 #3
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/247referenc...26/133439.aspx

--
Regards,

Phil Johnson (MCAD)
"Phil Johnson" wrote:
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.Inte rnalInvoke(IMethodCallMessage reqMcmMsg, Boolean useDispatchMessage, Int32 callType)
at System.Runtime.Remoting.Proxies.RemotingProxy.Invo ke(IMessage reqMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateI nvoke(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.HandleRe turnMessage(IMessage
reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateI nvoke(MessageData&
msgData, Int32 type)
at System.IO.MemoryStream.WriteTo(Stream stream)
at ConsoleApplication1.Class1.SaveMemoryStream(Memory Stream ms, String
FileName) in
c:\\hexagon\\hexagon.mycontainer\\consoleapplicati on\\class1.cs:line 160
at ConsoleApplication1.Class1.Main(String[] args) in
c:\\hexagon\\hexagon.mycontainer\\consoleapplicati on\\class1.cs:line
85" string

--
Regards,

Phil Johnson (MCAD)
"Ged" wrote:
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" <Ph*********@discussions.microsoft.comwrote in message
news:E1**********************************@microsof t.com...
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(objSeri alizedStream));
object objDeserialisedFile =
objDeserializer.Deserialize(objSerializedStream);
}
catch(Exception ex)
{
MessageBox.Show("Exception: " + ex.Message);
}
--
Regards,
>
Phil Johnson (MCAD)

Aug 23 '07 #4

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

Similar topics

2
by: Brad | last post by:
I have tried both the binary and the XML serialization; both give the same results. I have an object with a MemoryStream member. When I serialize and deserialize the object, the MemoryStream...
0
by: jr | last post by:
Hello, I have got a schema file "myschema.xsd" from my customer for which I must create xml files. I used xsd.exe to create a class for the schema. I fill an object for that class with data...
3
by: Kristian Kjems | last post by:
This is the example from MSDN where an object is serialized to a filestream: MySerializableClass myObject = new MySerializableClass(); // Insert code to set properties and fields of the object....
3
by: Jerry | last post by:
Hi, I have a class like the following: class A { private B _b; A (B b) { _b = b; } ...
3
by: Gordz | last post by:
I've been experiencing problems on some computers with XML Serialization. On some computers the files do not get created on the web server's hard drive and it's been driving me nuts trying to...
8
by: Frank Rizzo | last post by:
How do I serialize Font object into a string that I can store in either INI file or the registry (I know its a bad thing, but need to do it nevertheless). Then, also, how do I deserialize it from...
3
by: Jeff Richardson | last post by:
This is a repost from the InfoPath news group. Hi, I am writing a SharePoint application that works with InfoPath forms. When a user submits a completed InfoPath form to a forms library my code...
6
by: Val | last post by:
How can I serialize/deserialize an object into a string. Existing examples seem to be showing this operation for files only. Thansk
3
by: Andrew Robinson | last post by:
I am using the folllowing code to serialize a object to a byte array (byte). It works fine, but my resulting array is size is being rounded up to the next largest 32768 boundary. How can I...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.