Problem loading a .ten file

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Rogier
Newbie
Newbie
Posts: 9
Joined: Tue Jan 04, 2005 5:00 am
Contact:

Problem loading a .ten file

Post by Rogier » Wed Jan 05, 2005 4:29 pm

Hi,

I'm having some problems loading a .ten file from a stream.
Using the editor I saved a chart layout in .ten format.
This .ten file was then imported into a database blob field.

An .aspx file reads this field into a MemoryStream which is
loaded, using chart.import.template.load(stream), into a new Steema.TeeChart.Chart object.

This loading fails with a 'Object reference not set to an instance of an object' exception. :cry:

The number of bytes from the stream are exactly the same as
the original .ten file has, so no problems there I think.
As a matter of fact, just now I saved the stream from the database
to another .ten file and imported that from the editor and all works
fine.

Can you please help ? This is a crucial part of way I want to work
with this component.

Rogier

Marjan
Site Admin
Site Admin
Posts: 745
Joined: Fri Nov 07, 2003 5:00 am
Location: Slovenia
Contact:

Post by Marjan » Fri Jan 07, 2005 8:10 am

Hi.

When you load chart from a stream(blob), do you reset stream position to 0 before you load it ? Here is the correct code, copied from TeeChart examples:

Code: Select all

//  1) Save the template into a Stream...
			System.IO.MemoryStream stream = new System.IO.MemoryStream();
			try
			{
				// save only Chart and Series formatting, NOT including data
				tChart1.Export.Template.Save(stream);
				// 2) Load the template into other Chart...
				stream.Position = 0;
				tChart2.Import.Template.Load(stream);
				// restore the chart alignment (in this example)
				this.tChart2.Dock = DockStyle.Fill;
				// repaint the Chart
				this.tChart2.Refresh();
			}
			finally
			{
				// remove the stream, it's no longer necessary...
				stream.Close();
			}
Marjan Slatinek,
http://www.steema.com

Rogier
Newbie
Newbie
Posts: 9
Joined: Tue Jan 04, 2005 5:00 am
Contact:

Post by Rogier » Fri Jan 07, 2005 2:27 pm

I've put the position to 0 as you suggested, but that doesn't seem to help.
If I use the same stream to save the data to a file and then load it with
the editor, the template works just fine. Therefore I think it is not
the stream that is the problem.

I tried moving my code out of the ASP.Net context
and into an application to avoid IIS context problems, but
also in an application context the same error occurs.

Rogier
Newbie
Newbie
Posts: 9
Joined: Tue Jan 04, 2005 5:00 am
Contact:

Post by Rogier » Mon Jan 10, 2005 1:44 pm

I use the following code to get the stream from the database.
The database is a Microsoft SQLServer 2000.

Code: Select all

class Customer
{
    ...

    public Stream GetStream()
    {
        MemoryStream stream;
        LayoutDataLayer dal = 
             <CLASS THAT REPRESENTS THE DATABASE API>;
            
        ...
        
        // Only retrieve the bytes from the database the first time.
        if(null == this.layoutBytes)
        {
            this.layoutBytes = dal.GetLayoutBytes(Data.Id);
        }
    
        stream = new MemoryStream(this.layoutBytes);
   
        return stream;
    }
}
Further on in my application I have the following code:

Code: Select all

class LoadTemplateTask : ITask
{
    ...

    public void Execute()
    {
    
        this.layout = customer.GetLayout(this.templateIdentifier);
    
        using(Stream stream = layout.GetStream())
        {
            stream.Position = 0;
            chart.Import.Template.Load(stream);
        }
    
        chart.Width = width;
        chart.Height = height;
    }

    ...

}
When this code get's executed a NullReference Exception is thrown on the chart.Import.Template.Load(stream) line.

Rogier

Rogier
Newbie
Newbie
Posts: 9
Joined: Tue Jan 04, 2005 5:00 am
Contact:

Post by Rogier » Mon Jan 10, 2005 1:46 pm

A small note on the previous post, the first codeblock shows
a Customer class, this should be a Layout class.

Marjan
Site Admin
Site Admin
Posts: 745
Joined: Fri Nov 07, 2003 5:00 am
Location: Slovenia
Contact:

Post by Marjan » Tue Jan 18, 2005 1:49 pm

8128465 wrote:I've put the position to 0 as you suggested, but that doesn't seem to help.
If I use the same stream to save the data to a file and then load it with
the editor, the template works just fine. Therefore I think it is not
the stream that is the problem..
Hmm.. So the problem only occurs if you save chart, saved to a memory stream to database (blob) field ? If this is the case then (I'm guessing here) the problem is the blob does not contain only chart stream. Without actually debugging your application it's hard to tell. Perhaps the problem is in your specific database ? Try doing the same thing with other database type and it's blob fields. If it works then the problem is in database and how it stores binary values (stream cont.) to blob field.
Marjan Slatinek,
http://www.steema.com

Marjan
Site Admin
Site Admin
Posts: 745
Joined: Fri Nov 07, 2003 5:00 am
Location: Slovenia
Contact:

Post by Marjan » Tue Jan 18, 2005 1:54 pm

8128465 wrote:A small note on the previous post, the first codeblock shows
a Customer class, this should be a Layout class.
Ok, thanks. Still, I'm a bit puzzled why you get AV at Import call. Make sure chart and stream object are not null when you're calling the Import(stream) method. Also, stream contence should be the same you'd get if you'd save chart to a file stream (a good check if you want to see if there are any differences when you save to blob field).
Marjan Slatinek,
http://www.steema.com

Rogier
Newbie
Newbie
Posts: 9
Joined: Tue Jan 04, 2005 5:00 am
Contact:

Post by Rogier » Wed Jan 19, 2005 2:17 pm

<Previous Post>
The number of bytes from the stream are exactly the same as
the original .ten file has, so no problems there I think.
As a matter of fact, just now I saved the stream from the database
to another .ten file and imported that from the editor and all works
fine.
I also tried the following

Code: Select all

FileStream stream = new FileStream(@"C:\tijdnet.ten", System.IO.FileMode.Open);
stream.Position = 0;
This also generates the Null Reference Exception, but when I load
the file, using the editor, all works fine.

I don't think the problem is in the stream.
The stream saved to a file, then loaded in editor works fine but loaded
from within a ASP.Net context it crashes the Chart. It does not matter
if the stream came from a database, or from file, they both contain
the same collection of bytes.

Marjan
Site Admin
Site Admin
Posts: 745
Joined: Fri Nov 07, 2003 5:00 am
Location: Slovenia
Contact:

Post by Marjan » Thu Jan 20, 2005 2:49 pm

When exactly do you get the error ? During the load procedure or after you're trying to access some of tChart properties ?
Marjan Slatinek,
http://www.steema.com

Rogier
Newbie
Newbie
Posts: 9
Joined: Tue Jan 04, 2005 5:00 am
Contact:

Post by Rogier » Fri Jan 21, 2005 4:34 pm

During the execution of the load method.

Marjan
Site Admin
Site Admin
Posts: 745
Joined: Fri Nov 07, 2003 5:00 am
Location: Slovenia
Contact:

Post by Marjan » Tue Jan 25, 2005 10:03 am

Hi, Rogier.

Have you tried the example Chris posted at private newsgroup ? The "problem" is we're not able to replicate the problem you're having so it's a bit difficult to debug/find a cause of the problem.
Marjan Slatinek,
http://www.steema.com

Post Reply