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.
Export.Template.Save Not Working Correctly
-
- Guru
- Posts: 1603
- Joined: Fri Nov 15, 2002 12:00 am
Re: Export.Template.Save Not Working Correctly
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.
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.
Best Regards,
Christopher Ireland / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
Re: Export.Template.Save Not Working Correctly
Thank you, Christopher. I will pass this along to my colleagues and look forward to the next NuGet package release.
Kris
Kris
Re: Export.Template.Save Not Working Correctly
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.
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.
-
- Guru
- Posts: 1603
- Joined: Fri Nov 15, 2002 12:00 am
Re: Export.Template.Save Not Working Correctly
Hello Kris,
going back to the issue tracker issue id=2603, I see that the code there:
Works fine—is this the code that's not working at your end?
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);
}
Best Regards,
Christopher Ireland / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
Re: Export.Template.Save Not Working Correctly
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.
Regards,
Kris Culin
Bentley Systems, Inc.
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);
}
}
Kris Culin
Bentley Systems, Inc.
-
- Guru
- Posts: 1603
- Joined: Fri Nov 15, 2002 12:00 am
Re: Export.Template.Save Not Working Correctly
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:
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.
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();
}
Best Regards,
Christopher Ireland / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
Re: Export.Template.Save Not Working Correctly
Thank you, Christopher. We'll make the change locally until it is released officially.
Kris
Kris