XML Import error 4517 - Can some one explain

The Notes Help is not too helpful on this.

Here are the steps to reproduce it.

dim stream in globals section

Create a stream from the contents of a richtext item about 2mb xml in it.

Fill the stream with:

stream.writetext(doc.getitem(“Body”)

Then write this stream to a text file like below:

stream.position = 0

do while not eos

buff = stream.read(bytes)

outstream.write…

loop

etc.

then finally

Set importer = s.CreateDXLImporter(stream, Thisdb)

then in the process

command I get the error

ProcessDXLImporter2 @ line 46.

4517 - <?xml version='1.0'?>

A NotesStream object cannot be used for XML input or output if both binary and text operations have been applied since first opened

DXL importer operation failed

::