Welcome Guest Search | Active Topics | Sign In | Register

Error - This session is no longer valid. If you wish to reuse the session later, please consider calling GetCookies to retain th Options
Brian Bales
Posted: Thursday, December 20, 2012 9:34:48 AM
Rank: Newbie
Groups: Member

Joined: 12/20/2012
Posts: 4
Hi,

I get the following error on trying to convert HTML string to PDF


Server Error in '/test' Application.
This session is no longer valid. If you wish to reuse the session later, please consider calling GetCookies to retain the session cookies, then reuse these cookies through HtmlToPdfOptions.Cookies with another session. (6)
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: EO.Pdf.Internal.k1: This session is no longer valid. If you wish to reuse the session later, please consider calling GetCookies to retain the session cookies, then reuse these cookies through HtmlToPdfOptions.Cookies with another session. (6)

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[k1: This session is no longer valid. If you wish to reuse the session later, please consider calling GetCookies to retain the session cookies, then reuse these cookies through HtmlToPdfOptions.Cookies with another session. (6)]
EO.Pdf.Internal.lo.l() +89
EO.Pdf.Internal.lo.a(a A_0) +139
EO.Pdf.Internal.lo.a(cm A_0) +38
EO.Pdf.HtmlToPdfSession.Dispose() +100
EO.Pdf.HtmlToPdf.ConvertHtml(String html, PdfDocument doc, HtmlToPdfOptions options) +240
EO.Pdf.HtmlToPdf.ConvertHtml(String html, PdfDocument doc) +7
[.....]


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272



The version of EO.Pdf dll being used is - 4.0.41.2
There are no images used in the HTML. The HTML string itself is dynamically generated. The above error doesn't happen all the time and there doesn't seem to be a regular pattern, but happens generally when the HTML size starts to get bigger. The HTML wouldn't be bigger than few KBs.


Below is the code that is being used

SetEoHtmlToPdfLicense();
HtmlToPdf.Options.BaseUrl = HttpContextFactory.Current.Request.Url.GetLeftPart(UriPartial.Authority) +
VirtualPathUtility.ToAbsolute("~/");
HtmlToPdf.Options.PageSize = PdfPageSizes.A4;
HtmlToPdf.Options.MaxLoadWaitTime = 120000;

//Convert the Url to PdfDocument
var doc = new PdfDocument();

HtmlToPdf.ConvertHtml(html, doc);
HttpContextFactory.Current.Response.Clear();
HttpContextFactory.Current.Response.ClearHeaders();
HttpContextFactory.Current.Response.ContentType = "Application/pdf";
HttpContextFactory.Current.Response.AddHeader("Content-Disposition",
string.Format("Attachment;Filename=export_{0}.pdf",
DateTime.Now));
doc.Save(HttpContextFactory.Current.Response.OutputStream);
HttpContextFactory.Current.Response.End();


I have seen other posts in the forum, suggesting the usage of the latest build. But my version seems to be much latest than what is seen in those posts.

Appreciate your help in fixing the issue as soon as possible.


eo_support
Posted: Thursday, December 20, 2012 9:53:18 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Hi,

Please still try to update to the latest build first. You will also want to try to use ASPXToPDF instead of ConvertHtml. The reason is if your ConvertHtml access other resources from the same application where you call ConvertHtml, you may run into session lock or synchronization issues, which can cause all kind of strange errors.

If you still prefer to use ConvertHtml, try to find out which part inside the HTML is triggering that problem. Once you find that out, try to create a separate test application and see if you can duplicate the problem there. Usually we can get to the bottom of it as soon as you can duplicate the problem.

Thanks!
Brian Bales
Posted: Thursday, December 20, 2012 9:32:02 PM
Rank: Newbie
Groups: Member

Joined: 12/20/2012
Posts: 4
Thanks for the reply.

I guess, I cannot use ASPXToPDF since the documentation says, "ASPXToPDF is an ASP.NET server control that allows you to render the current page as PDF". In my scenario, it is not the current page which needs to be converted. It is more like exporting search results to PDF. The user has an option to select how much ever search results to export to PDF. When the number of results is 10-15, the conversion works most of the time, but I have seen it fail. On other times, the conversion works fine when the number of results is 150 odd. The HTML has mere text, nothing else.

What do you mean by trying to find out which part inside the HTML triggers the problem? You mean to look out for a certain tag? What inside the HTML is likely to cause such an error?

Brian Bales
Posted: Friday, December 21, 2012 5:22:31 AM
Rank: Newbie
Groups: Member

Joined: 12/20/2012
Posts: 4
Now I got the below error while trying to use ConvertUrl. Is this a memory problem?


Server Error in '/test' Application.
Buffer cannot be null.
Parameter name: buffer
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentNullException: Buffer cannot be null.
Parameter name: buffer

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[ArgumentNullException: Buffer cannot be null.
Parameter name: buffer]
System.IO.MemoryStream..ctor(Byte[] buffer, Boolean writable) +9635863
System.IO.MemoryStream..ctor(Byte[] buffer) +6
EO.Pdf.Internal.be.a(Byte[] A_0, Single A_1, Single A_2, Single A_3, Single A_4, Double A_5, Double A_6) +77
EO.Pdf.Internal.lt.b(String A_0) +290
EO.Pdf.Internal.lt.d() +133

[HtmlToPdfException: Convertion failed. Buffer cannot be null.
Parameter name: buffer]
EO.Pdf.HtmlToPdfException.b(Exception A_0) +65
EO.Pdf.Internal.lt.d() +1143
EO.Pdf.HtmlToPdfSession.RenderAsPDF(PdfDocument doc) +50
EO.Pdf.HtmlToPdf.ConvertUrl(String url, PdfDocument doc, HtmlToPdfOptions options) +105
EO.Pdf.HtmlToPdf.ConvertUrl(String url, PdfDocument doc) +7
eo_support
Posted: Friday, December 21, 2012 9:16:32 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Hi,

"This session is no longer valid error" usually occurs when you create a HtmlToPdfSession object, but didn't use it for a while and then try to use it. This can also occur if one conversion takes a long time.

What I meant is by "trying to find out which part inside the HTML triggers the problem", I meant that there maybe something in your HTML that triggers certain request on your server that can cause problem for you. One example is, if you have something like this in your HTML:

Code: HTML/ASPX
<iframe src=”LogMeout.aspx” />


Then the converter will request that page, which runs the code associated to that page on the server and (presumably) cause you to log yourself out. Obviously if you have another request in the HTML block that requires user to be logged in, then you will have trouble. So the idea is to first find out what triggered the problem first.

As to the “buffer can not be null” problem, we do not know what’s causing it. If you can reproduce it and send us a test project, we will be very happy to take a look.

Thanks!
Brian Bales
Posted: Friday, December 21, 2012 1:21:09 PM
Rank: Newbie
Groups: Member

Joined: 12/20/2012
Posts: 4
Thanks for the reply.

I managed to fix the problem, by moving the references to external CSS, locally inside the HTML. From your hint above, I suppose may be the call to the external CSS is going through an HttpModule in the application which uses Sessions.

Anyhow, I found that moving the few CSS styles internally reduces the size of the HTML considerably as well. I tried multiple times to export with different types of HTML and so far it all worked! :-)

Thanks once again!
eo_support
Posted: Friday, December 21, 2012 1:24:20 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Great. Glad to hear that it worked for you!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.