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

XSD validation gives closed stream.

Hi to all,

I have a memory Stream that is validated using the XmlValidatingReader
object. My stream is passed to the XmlValidatingReader object together with
the xsd file. This works fine.

Once validated (and there are no errors), I want to use the same stream in
other piece of functionality. As soon as I access this stream I get the
error "System.objectDispose exception. Cannot access a closed stream". I get
the same error if I used a fileStream (in this case I get cannot access a
closed file error). I tried stream.seek(0,0) before accessing it but I then
get the same error at the seek line.

Any clues on what the problem is?

Sham.
Nov 21 '06 #1
4 3272
sham wrote:

I have a memory Stream that is validated using the XmlValidatingReader
object. My stream is passed to the XmlValidatingReader object together with
the xsd file. This works fine.

Once validated (and there are no errors), I want to use the same stream in
other piece of functionality. As soon as I access this stream I get the
error "System.objectDispose exception. Cannot access a closed stream". I get
the same error if I used a fileStream (in this case I get cannot access a
closed file error). I tried stream.seek(0,0) before accessing it but I then
get the same error at the seek line.

Any clues on what the problem is?
With .NET 2.0 you can use XmlReaderSettings with CloseInput set to false
<http://msdn2.microsoft.com/en-us/library/system.xml.xmlreadersettings.closeinput.aspx>
XmlValidatingReader also has a property Settings so you can use e.g.
XmlValidatingReaderInstance.Settings.CloseInput = false
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 21 '06 #2
"sham" <sh******@inspirationmatters.comwrote in message
news:eD**************@TK2MSFTNGP06.phx.gbl...
Hi to all,

I have a memory Stream that is validated using the XmlValidatingReader
object. My stream is passed to the XmlValidatingReader object together
with the xsd file. This works fine.

Once validated (and there are no errors), I want to use the same stream in
other piece of functionality. As soon as I access this stream I get the
error "System.objectDispose exception. Cannot access a closed stream". I
get the same error if I used a fileStream (in this case I get cannot
access a closed file error). I tried stream.seek(0,0) before accessing it
but I then get the same error at the seek line.

Any clues on what the problem is?
Yes. You closed the stream.

Did you use the stream inside of a using block?

John
Nov 21 '06 #3
I am currently using .net 1.1
What are my options to not close the stream? (apart from creating another
stream).

No I am not using a using block. It looks as thought the xmlValidatingReader
is closing the stream.

Sham.

"John Saunders" <john.saunders at trizetto.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
"sham" <sh******@inspirationmatters.comwrote in message
news:eD**************@TK2MSFTNGP06.phx.gbl...
>Hi to all,

I have a memory Stream that is validated using the XmlValidatingReader
object. My stream is passed to the XmlValidatingReader object together
with the xsd file. This works fine.

Once validated (and there are no errors), I want to use the same stream
in other piece of functionality. As soon as I access this stream I get
the error "System.objectDispose exception. Cannot access a closed
stream". I get the same error if I used a fileStream (in this case I get
cannot access a closed file error). I tried stream.seek(0,0) before
accessing it but I then get the same error at the seek line.

Any clues on what the problem is?

Yes. You closed the stream.

Did you use the stream inside of a using block?

John


Nov 21 '06 #4
sham wrote:
I am currently using .net 1.1
What are my options to not close the stream? (apart from creating another
stream).

No I am not using a using block. It looks as thought the xmlValidatingReader
is closing the stream.
Yes, it is documented
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemXmlXmlValidatingReaderClassCloseTopic.a sp>
that "If this reader was constructed using a stream, this method also
calls Close on the underlying stream."
It looks as if the only way is not calling the Close method on the
XmlValidatingReader until you know you do not longer need the memory
stream. On the other hand that does sound like a good idea in general to
not close the reader when you are finished with it.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 21 '06 #5

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

Similar topics

0
by: Marco Nicosia | last post by:
Hello gang, My coworker and I are writing a Python class for the other developers within our team. This class is supposed to encapsulate several things, including daemonizing, setting up...
2
by: Shone | last post by:
I would like to perform a 2-pass XML reading from a stream. Once using the Validating reader, just to confirm the validity against the schema, and next time to do a reading to extract the data....
26
by: Rajeev Tipnis | last post by:
http://support.microsoft.com/default.aspx?scid=kb;en- us;819450 Questions: 1) Is this patch (fix) applicable to the .NET 1.1 Framework as well? That is, if we have Framework 1.1 (On...
5
by: Micky | last post by:
VB v7.1.3088 NET v1.1.4322 SP1 My mate has a strange problem regarding the ESC key and validation. When he hits the Cancel button on his form, the form does not validate. This is correct...
8
by: Marc Gravell | last post by:
I want to write a method that will accept a stream as a parameter, and which will write xml to the stream (based in reality on database results) using the XmlTextWriter class. However, this insists...
1
by: Lee Crabtree | last post by:
Is there some way to find out if a stream is already open? In particular, I want to be able to switch from a NetworkStream to a FileStream depending on input. I know I can use a Stream object and...
6
by: Rob Meade | last post by:
Hi all, I'm having a few difficulties with the above, ie I cant find any good examples anywhere of how to do what I want to do! I have an xml file on my desktop which I want to read in. ...
4
by: Gary Wessle | last post by:
Hi please look at the code below, the problem I have is that line 37 does not print out into the file as expected. however if I move it to be immediately after line 16 it prints fine into the...
3
by: madumm | last post by:
Hi All; I was trying to get this "source" into a BufferedReader ; but when running it gives a Exception as follows:...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.