Hi,
Thanks for your posting and using Aspose.Cells for .NET.
Please download and try the latest version: Aspose.Cells
for .NET v7.5.0.4 and see if it resolves your issue.
If your problem still persists, then please provide us your source file and the runnable sample code replicating this issue with the latest version. We will look into it and help you asap.
Hello.
var loadOptions = new LoadOptions(LoadFormat.Xlsx);
var dataOption = new LoadDataOption();
dataOption.ImportFormula = true;
loadOptions.LoadDataOnly = false;
loadOptions.LoadDataOptions = dataOption;
Workbook wb = new Workbook(@“C:\Users.…\Survey.xlsx”, loadOptions);<span style="color:blue;">var</span> sheet = wb.Worksheets[0]; <span style="color:blue;">var</span> chart = sheet.Charts[0]; <pre style="font-family: Consolas; background-position: initial initial; background-repeat: initial initial;"> lCh.PrintSize = <span style="color:#2b91af;">PrintSizeType</span>.Custom; lCh.ChartObject.Height = 280; lCh.ChartObject.Width = 400; lCh.ChartArea.Border.IsVisible = <span style="color:blue;">false</span>; <span style="color:green;">// Remove border.</span> <span style="color:blue;">if</span> (lCh.CategoryAxis != <span style="color:blue;">null</span>) lCh.CategoryAxis.TickLabels.RotationAngle = 0; <span style="color:blue;">try</span> { lCh.Calculate(); }</pre> <span style="color:blue;">var</span> lMs = <span style="color:blue;">new</span> <span style="color:#2b91af;">MemoryStream</span>(); { chart.ToImage(lMs, <span style="color:#2b91af;">ImageFormat</span>.Emf); lMs.Position = 0; <span style="color:blue;">var</span> img = <span style="color:#2b91af;">Image</span>.FromStream(lMs); }</pre></div><div><br></div><div>With this you will be able to reproduce the new exception that I get. The chart has over 690 categories. I don't know if this is causing some problems. But I have the impression that only the number of series of the chart is limitted to 256 series maxmum, right?<br>I have noticed that when I specify small dimensions for the image, I get no exception.<br>But I want my image to be large.</div><div><br></div><div>Note that both methods <span style="font-family: Consolas; font-size: 13px;">Calculate() and </span><span style="background-color: white; font-family: Consolas; font-size: 13px;">ToImage() </span>throw an exception:</div><div><br>{"Object reference not set to an instance of an object."}</div><div><span style="background-color: white; font-family: Consolas; font-size: 13px;"><div> at . . ( , String , Int32 , Font , SizeF , , )</div><div> at . . ( , , Rectangle , Rectangle , Int32 , Boolean , )</div><div> at . .Calculate( )</div><div> at . . ( )</div><div> at . .Calculate()</div><div> at . . (Chart )</div><div> at . . (Chart , Boolean )</div><div> at . .Calculate(Chart , Boolean )</div><div> at Aspose.Cells.Charts.Chart.Calculate(Boolean , Boolean )</div><div> at Aspose.Cells.Charts.Chart.Calculate()</div><div> at del7.Form1.button1_Click(Object sender, EventArgs e) in c:\Users\...\del7\del7\Form1.cs:line 34</div><div><br></div></span></div><div><span style="background-color: white; font-family: Consolas; font-size: 13px;"><br></span></div><div><span style="background-color: white; font-family: Consolas; font-size: 13px;"><div> at . . ( , String , Int32 , Font , SizeF , , )</div><div> at . . ( , , Rectangle , Rectangle , Int32 , Boolean , )</div><div> at . .Calculate( )</div><div> at . . ( )</div><div> at . . ()</div><div> at . . ()</div><div> at . .ToImage(Stream , ImageFormat , Chart )</div><div> at Aspose.Cells.Charts.Chart.ToImage(Stream stream, ImageFormat imageFormat)</div><div> at del7.Form1.button1_Click(Object sender, EventArgs e) in c:\Users\...\del7\del7\Form1.cs:line 39</div></span></div><div><br></div><div>Please, let me know of any workarounds or fixes to this.</div><div><br></div><div>Best Regards,</div><div>Kostas</div></div>
Hi,
Hello there,
I am experiencing exact same issue (Object reference not set to an instance of an objectv) while exporting charts with say 200 categories.
This is causing big problem for us as we are already live with ASPOSE components on production.
Any quick fix will be really appreciated.
Thanks
Imran
Hi Imran,
Hello.
It seems that the exception doesn’t appear when I remove the following line:
if (lCh.CategoryAxis != null) lCh.CategoryAxis.TickLabels.RotationAngle = 0;
But there is a reason that I have this line.
A display bug appears when not added (sometimes the tick labels get rotated at 90 degree angle when converting to image).
I can’t have this random behaviour, that’s why I set the rotation angle to 0.
Why does this generate the problem?
Best Regards,
Kostas
In fact, every angle except 0 and 90 doesn’t make the exception to appear.
Hi,
Hi,
Thanks for your posting and using Aspose.Cells for .NET.
Please download and try this fix: Aspose.Cells for .NET v7.5.0.5 and let us know your feedback.
The issues you have found earlier (filed as CELLSNET-41808) have been fixed in this update.
This message was posted using Notification2Forum from Downloads module by Aspose Notifier.
Hello.
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Hi,
Thanks for your posting and using Aspose.Cells for .NET.
Could you please download and try the latest version Aspose.Cells
for .NET v7.5.2.2 and let us know your feedback?
I have tested your issue with the latest version and it generates some different exception. Could you let us know run results at your end? We will log it in our database for a fix.
Hi.
Hi,
Thanks for your feedback and using Aspose.Cells.
We were able to observe the exceptions with v7.5.2 and v7.5.2.2. We have logged this issue in our database for investigation. We will look into it and fix this issue. Once, the issue is resolved or we have some other update for you, we will let you know asap.
This issue has been logged as CELLSNET-41986.
Hi,
Thanks for using Aspose.Cells.
We have checked the project you provided. We found the resources are not released in the project. At the same time it is best saving chart to file, please use Chart.Tomage() directly.
C#
for (int i = 0; i < 10; i++)
{
using (var lMs = new MemoryStream())
{
{
if (lCh.Type == ChartType.Area)
{
bool re = lCh.NSeries.CategoryData == null;
}
lCh.ToImage(lMs, ImageFormat.Emf);
if (lMs.Length != 0)
{
lMs.Position = 0;
using (var img = Image.FromStream(lMs))
{
string bookName = Path.GetFileName(oneXlsx);
string name = @“D:\Aspose\User\0643\del7\File”
+ bookName + “" + lWks.Name + "” + chartIndex.ToString()
+ “_” + i.ToString() + “.emf”;
//Don’t use the for saving chart to file
//img.Save(name, ImageFormat.Emf);
//Use the method to replace the upper
lCh.ToImage(name, ImageFormat.Emf);
//Please release the resource
lMs.Close();
img.Dispose();
}
}
}
}
}
Hello.
Yes, I don’t save the images directly with Chart.Tomage() because this was a simple demo immitating a real project.
In my real project I insert them into a DOCX document.
Also, the reason that I don’t release the memory stream (although here I could) is because in my real project I can’t do it immediately, since MS say so:
Quote: “You must keep the stream open for the lifetime of the Image.”
However, all these have nothing to do with the problem.
Did you find anything concerning the access violations and heap corruptions?
Perhaps it’s a shared static variable or shared (between the threads) object in Aspose Cells that causes this.
This seems to be a threading problem, since it is only reproduced when multiple threads use the convertion to image functionality.
If you make the loop of your code multithreaded it will be crashing again.
Please, find what these threads use in common and you will find the problem.
Normally, they should not use the same objects and if they need to do so they must be synchronized somehow.
Kostas.
Hi,
Thanks for your posting and using Aspose.Cells.
Well, it seems your problem is related to multithreading and not freeing the resources. It is not related to Aspose.Cells. However, we have logged your comment in our database. We will look into it and advise you if possible. Once, we will have some update for you, we will let you know asap.
Hi.
Hi,
Thanks for your posting and using Aspose.Cells.
We have already logged your comment in our database. Please spare us some time. Once, there is some fix or update for you, we will let you know asap.
Hi Kostas,
Thanks for using Aspose.Cells.
We created a simple project which is not dependent on Aspose.Cells to reproduce the AccessVoilationException.
As MSDN (http://msdn.microsoft.com/en-us/library/windows/desktop/ms684256(v=vs.85).aspx
) says, multiple threads can’t share GDI+ objects. So we must lock the drawing function, like TestLock() method in SimpleTest.
We try to separate the GDI objects using in Chart.ToImage() and add a lock for every one of them, but didn’t succeed. There are too many GDI objects being used in ToImage(), we even can’t discriminate them. You may add a lock to Chart.ToImage() method.