Export.Template.Save Not Working Correctly

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Kris C
Newbie
Newbie
Posts: 59
Joined: Fri Jan 13, 2023 12:00 am

Export.Template.Save Not Working Correctly

Post by Kris C » Thu Apr 13, 2023 7:32 pm

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.

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Export.Template.Save Not Working Correctly

Post by Christopher » Fri Apr 14, 2023 10:25 am

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.
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

Kris C
Newbie
Newbie
Posts: 59
Joined: Fri Jan 13, 2023 12:00 am

Re: Export.Template.Save Not Working Correctly

Post by Kris C » Fri Apr 14, 2023 11:52 am

Thank you, Christopher. I will pass this along to my colleagues and look forward to the next NuGet package release.

Kris

Kris C
Newbie
Newbie
Posts: 59
Joined: Fri Jan 13, 2023 12:00 am

Re: Export.Template.Save Not Working Correctly

Post by Kris C » Mon Apr 24, 2023 6:51 pm

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.

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Export.Template.Save Not Working Correctly

Post by Christopher » Tue Apr 25, 2023 7:08 am

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?
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

Kris C
Newbie
Newbie
Posts: 59
Joined: Fri Jan 13, 2023 12:00 am

Re: Export.Template.Save Not Working Correctly

Post by Kris C » Tue Apr 25, 2023 10:36 am

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.

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Export.Template.Save Not Working Correctly

Post by Christopher » Tue Apr 25, 2023 10:58 am

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.
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

Kris C
Newbie
Newbie
Posts: 59
Joined: Fri Jan 13, 2023 12:00 am

Re: Export.Template.Save Not Working Correctly

Post by Kris C » Tue Apr 25, 2023 11:41 am

Thank you, Christopher. We'll make the change locally until it is released officially.

Kris

Post Reply