Problem loading a .ten file
Problem loading a .ten file
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.
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
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.
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
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:
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
http://www.steema.com
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.
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.
I use the following code to get the stream from the database.
The database is a Microsoft SQLServer 2000.
Further on in my application I have the following code:
When this code get's executed a NullReference Exception is thrown on the chart.Import.Template.Load(stream) line.
Rogier
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;
}
}
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;
}
...
}
Rogier
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.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..
Marjan Slatinek,
http://www.steema.com
http://www.steema.com
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).8128465 wrote:A small note on the previous post, the first codeblock shows
a Customer class, this should be a Layout class.
Marjan Slatinek,
http://www.steema.com
http://www.steema.com
I also tried the following<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.
Code: Select all
FileStream stream = new FileStream(@"C:\tijdnet.ten", System.IO.FileMode.Open);
stream.Position = 0;
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.
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
http://www.steema.com
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.
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
http://www.steema.com