Page 1 of 1
Export.Template.Save Not Working Correctly
Posted: Thu Apr 13, 2023 7:32 pm
by 16095093
Hello,
I've uploaded TeeChartStreamProblem.zip via the upload service under
kris.culin@bentley.com.
When running in
net6 and you call Export.Template.Save with a MemoryStream, it will be immediately closed and any attempt to read it throws an exception.
The same exact code works in net472.
Is this behavior a bug or is there a different approach that is required for net6?
Kris Culin
Bentley Systems, Inc.
Re: Export.Template.Save Not Working Correctly
Posted: Fri Apr 14, 2023 10:25 am
by Christopher
Hello Kris,
thank you for reporting this issue to us; I have added it to our issue tracker with
id=2603. As you can read, there are two errors in the latest NuGet package, the first to do with a missing reference to System.Text.Json, and the second with a reference to Steema.TeeChart.Drawing.IAxisLinePen. We will fix these issues as soon as possible and include them in an upcoming NuGet release.
Re: Export.Template.Save Not Working Correctly
Posted: Fri Apr 14, 2023 11:52 am
by 16095093
Thank you, Christopher. I will pass this along to my colleagues and look forward to the next NuGet package release.
Kris
Re: Export.Template.Save Not Working Correctly
Posted: Mon Apr 24, 2023 6:51 pm
by 16095093
Hi Christopher,
After updating to the latest TeeChart 6.2023.4.20, I've been checking to make sure the bugs we've reported are resolved (we have our own bug tracking system associated with these issues that need to be marked resolved).
The bug related to Export.Template.Save appears to be unfixed. We are still getting the ObjectDisposedException after using Template.Save with a MemoryStream.
If you need more details beyond the sample project we uploaded earlier, or another sample project, please let me know.
Thanks,
Kris Culin
Bentley Systems, Inc.
Re: Export.Template.Save Not Working Correctly
Posted: Tue Apr 25, 2023 7:08 am
by Christopher
Hello Kris,
going back to the issue tracker issue
id=2603, I see that the code there:
Code: Select all
private async void button1_Click(object sender, EventArgs e)
{
var export = tChart1.Export.Template;
var import = tChart2.Import.Template;
var stream = new MemoryStream();
await export.SaveAsync(stream);
stream.Position = 0;
await import.LoadAsync(stream);
}
Works fineāis this the code that's not working at your end?
Re: Export.Template.Save Not Working Correctly
Posted: Tue Apr 25, 2023 10:36 am
by 16095093
Hi Christopher,
Sorry for the delayed response but I wanted to verify what we were calling first before I responded.
We are using the tChart1.Export.Template.Save method and passing in an instance of a MemoryStream, not the SaveAsync method. In your implementation of the Save method, you are using a "using" block for the StreamWriter. AS a result, it is disposing the stream that is passed in - in this case that would be the MemoryStream we are creating. When the MemoryStream is disposed (closed), it can no longer be used. The SaveAsync method does not use the "using" block.
The net472 version apparently did not use the "using" block for the Save method.
Code: Select all
private async void button1_Click(object sender, EventArgs e)
{
var export = tChart1.Export.Template;
var import = tChart2.Import.Template;
var stream = new MemoryStream();
export.Save(stream);
if (stream.Length > 0) // Will blow up with an ObjectDisposedException here.
{
stream.Position = 0;
import.Load(stream);
}
}
Regards,
Kris Culin
Bentley Systems, Inc.
Re: Export.Template.Save Not Working Correctly
Posted: Tue Apr 25, 2023 10:58 am
by Christopher
Hi Kris,
I think you should be fine working with SaveAsync, but if for whatever reason you want to work with Save for a MemoryStream (instead of Save for a fileName), then you can made the change in the sourcecode you have:
Code: Select all
public void Save(Stream stream)
{
//using (var writer = new StreamWriter(stream))
//{
// writer.Write(JsonSerializer.Serialize<Chart>(_chart, Options));
//}
var writer = new StreamWriter(stream);
writer.Write(JsonSerializer.Serialize<Chart>(_chart, Options));
writer.Flush();
}
This is less efficient memory-wise (and already works fine with a fileName/FileStream, just as SaveAsync already works with MemoryStream), but I'll make this change to our sourcecode anyhow, meaning it will be available in the future.
Re: Export.Template.Save Not Working Correctly
Posted: Tue Apr 25, 2023 11:41 am
by 16095093
Thank you, Christopher. We'll make the change locally until it is released officially.
Kris