Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get error when use memory stream to read files #353

Closed
farshadvl opened this issue Jun 3, 2024 · 3 comments · Fixed by #383
Closed

get error when use memory stream to read files #353

farshadvl opened this issue Jun 3, 2024 · 3 comments · Fixed by #383
Labels
bug Something isn't working

Comments

@farshadvl
Copy link

farshadvl commented Jun 3, 2024

hi
I use acadsharp to read dwg files and do some process like dxf files on it.
my code:
using (MemoryStream ms = new MemoryStream())
{
using (DxfWriter writer = new DxfWriter(ms, doc, false))
{
writer.OnNotification += onNotification;
writer.Write();
}
}

it get error : Cannot access a closed Stream.

what should I do?

@farshadvl farshadvl added the bug Something isn't working label Jun 3, 2024
@Revan1985
Copy link

Hi @farshadvl
are you sure you want to read a file?
Class DxfWriter is used to write, you should use class DxfReader.

@DomCR
Copy link
Owner

DomCR commented Jun 3, 2024

Hi @farshadvl,

As @Revan1985 pointed out your piece of code seems to be incomplete for us to help, but for what you are saying you are trying to read information from a closed Stream, if that's the case try to create a copy of the same stream:

	using (MemoryStream ms = new MemoryStream())
	{
		CadDocument doc = new CadDocument();

		using (DxfWriter writer = new DxfWriter(ms, doc, false))
		{
			writer.CloseStream = false;
			writer.Write();
		}

		MemoryStream s = new MemoryStream(ms.ToArray());

		using(DxfReader reader = new DxfReader(s))
		{
			CadDocument output = reader.Read();
		}
	}

I'm not sure if this is what you are trying to achieve, let me know if this helps.

@DomCR
Copy link
Owner

DomCR commented Jun 3, 2024

I've also noticed that the writer closes the stream even if the CloseStream flag is set to false, I'll open a branch to fix it, in the mean time the code that I've provided should help.

@DomCR DomCR linked a pull request Jul 18, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants