Is there a way to use the doc tag inside of a foreach loop using .NET

I’m trying to load a document, using streams, inside of a foreach loop. The stream is
being specified in the DataSources array. The doc tag is specifying the -build switch. When trying this I get a “Cannot access a closed file error.” I’m assuming that’s because the loaded file is closed by the assembler as soon as the corresponding document is loaded.

Is there a way I can make this work?

1 Like

@dsmeltz,

We are looking into this scenario. Your investigation ticket ID is ASSEMBLYNET-157. As there’s any update, you’ll be notified.

@dsmeltz,

Yes, the stream is closed as soon as the document is loaded, so the same stream instance cannot be used multiple times (i.e. in a loop) to load documents. In order to avoid this restriction there’s a workaround, you may use one of the following objects instead of a stream:

  1. A string containing a file name or URI or Base64-encoded document data
  2. A byte array (it can be achieved upon reading the stream)
  3. An object providing a new stream instance on every iteration as shown in the following code snippet

Have a look at code below:

public class StreamProvider
{
    public Stream Stream 
    { 
        get { return /* TODO: A new stream instance should be initialized here upon your requirements. */; } 
    }
}

In the latter case, given that p stands for an instance of StreamProvider, the following tag can be used to insert a document:

<<doc [p.Stream]>>