0
votes

I'm using localReport to print PDF (SQL REPORTVIEWER). It works fine on localhost. When I move the application to Production (64 bits windows 2008) it gives me an error. (see below)

I put the renderedbytes in a Session in USERCONTROL and I do window.open('Program1.aspx')...

In page load of Program1.aspx I try to retrieve the Session variable and process.... I think this statement cause the error "Response.BinaryWrite (...) etc".

It works on my local pc (Vista 32bits)...

Can someone please what the errors says? and How can I solve this on production??????

thank you..

USERCONTROL1.ASCX

byte[] renderedBytes;

        renderedBytes = localReport.Render(
            reportType,

            deviceInfo,

            out mimeType,

            out encoding,

            out fileNameExtension,

            out streams,

            out warnings);

 Session["report"] = Print.RenderReport(listEnt, Language);

PROGRAM2.ASPX

    protected void Page_Load(object sender, EventArgs e)
    {

        string extension = "PDF";

        Response.ContentType = "application/pdf";

        // set the MIME type here

        Response.AddHeader("content-disposition", "inline: filename=Test." + extension);

        Response.BinaryWrite((byte[])Session["report"]);
        Response.End();

    }

Server Error in '/' Application. Object reference not set to an instance of an object. 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.NullReferenceException: Object reference not set to an instance of an object.

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:

[NullReferenceException: Object reference not set to an instance of an object.] System.Web.HttpResponse.BinaryWrite(Byte[] buffer) +13 ConfederatieBouw.CustomModules.Controle_InhoudingsPlicht.WebForm1.Page_Load(Object sender, EventArgs e) +191 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35 System.Web.UI.Control.OnLoad(EventArgs e) +99 System.Web.UI.Control.LoadRecursive() +50 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsync

2
Shouldn't you be setting Session["report"] = renderedBytes ? otherwise, why are you setting that variable and not using it?willvv
Good point willvv, but even if that function is returning something other than byte[], it isn't the immediate problem, as the user is getting a NullReferenceException. If they were trying to cast something that isn't a byte[], they would be getting an InvalidCastException. It is entirely possible once they clear up the current error, that may be the next one they are getting.Brian Ball

2 Answers

1
votes

Are you running a web farm in production? If so, how are you storing session state? The default is InProc, which means the session will only exist on one server in the farm, and if the follow up request goes to another server, that would explain the issue. The fix this scenario, you will need to setup some sort of session state that can be shared across servers (such as a session state server or SQL Server session state).

Here is some info on the various session state providers: http://msdn.microsoft.com/en-us/library/ms178586.aspx

0
votes

Session["report"] is null. You're not setting it to renderBytes in the user control.

Also, it's a really bad idea to store this in a Session. Your binary data has to be serialized/encoded and then deserialized/unencoded whenever you set the Session[] value, which performs poorly. Create a property on the user control to accept the report object and write it to the output stream there, or just do it in the page itself. I'm not sure that it makes sense to put this in a user control instead of a regulat class, anyway.