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
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
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.
Related
I'm currently working on a series of webforms that when clicked through in the right order, information is stored into a Session. If a user goes to this page directly I want to redirect them back to the first webform page. I can get this
When I run this code locally on my machine, the Session is null and the if/else statement works, redirecting to default.aspx. However when I load the files to the server and run from the webpage I get a Object reference not set to an instance of an object. error.
protected void Page_Load(object sender, EventArgs e)
{
if (Session != null && Session["ReasonForAdminRights"] != null)
{
ll.Text = Session["ReasonForAdminRights"].ToString();
}
else
{
Response.Redirect("~/default.aspx");
}
}
I've tried a number of variations without any luck, including:
if (!string.IsNullOrEmpty(Session["ReasonForAdminRights"] as string))
{
ll.Text = ((string)Session["ReasonForAdminRights"]);
}
And
if (Session["ReasonForAdminRights"] != null)
I've done some Googling and the answers on Stackoverflow have told me that the session object isn't correctly set. But I'm stuck as to how to debug it further on the server? I don't know how to find out what's actually in there, as it should be null so should always go to the else statement.
Any help would be appreciated! I'm at a bit of a loss!
Answers tried:
What does "Object reference not set to an instance of an object" mean?
What is a NullReferenceException, and how do I fix it?
Object reference not set to an instance of an object.
EDIT
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
ServiceDeskHelpForms.user_details_collection.Page_Load(Object sender, EventArgs e) in \\homes\My Documents\Visual Studio 2015\Projects\SDHelpForms\SDHelpForms\user-details-collection.aspx.cs:24
System.Web.UI.Control.OnLoad(EventArgs e) +108
System.Web.UI.Control.LoadRecursive() +67
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+4497
Note: Answer based on commment trail on question
The problem is likely caused by a broken installation on the server. A complete wipe + redeploy on the server may fix the problem.
var sessionValue= (string)(Session["ReasonForAdminRights"]);
if(!string.IsNullOrEmpty(sessionValue))
{
//do something...
}
NET application that was running on Windows Server 2003 and now it's been upgraded to Windows Server 2012.
The application has several report made in Crystal Report and whenever those reports are fed a dataset I get the following error:
Error in File C:\Windows\TEMP\temp_8906e55c-36b9-40f1-8385-7bf2fafe324c {9D8F44CC-FC36-4F28-916B-DAD28922C786}.rpt:
The request could not be submitted for background processing.
[COMException (0x800002ad):
Error in File C:\Windows\TEMP\temp_8906e55c-36b9-40f1-8385-7bf2fafe324c {9D8F44CC-FC36-4F28-916B-DAD28922C786}.rpt:
The request could not be submitted for background processing.]
CrystalDecisions.ReportAppServer.Controllers.DatabaseControllerClass.ReplaceConnection(Object oldConnection, Object newConnection, Object parameterFields, Object crDBOptionUseDefault) +0
CrystalDecisions.CrystalReports.Engine.Table.SetDataSource(Object val, Type type) +1084
CrystalDecisions.CrystalReports.Engine.ReportDocument.SetDataSourceInternal(Object val, Type type) +280
[InternalException:
Error in File C:\Windows\TEMP\temp_8906e55c-36b9-40f1-8385-7bf2fafe324c {9D8F44CC-FC36-4F28-916B-DAD28922C786}.rpt:
The request could not be submitted for background processing.]
CrystalDecisions.ReportAppServer.ConvertDotNetToErom.ThrowDotNetException(Exception e) +789
CrystalDecisions.CrystalReports.Engine.ReportDocument.SetDataSourceInternal(Object val, Type type) +327
CrystalDecisions.CrystalReports.Engine.ReportDocument.SetDataSource(DataSet dataSet) +91
CCD.Tresorerie.SWAP.Reports.ReportExtensions.SetSQLQuery(ReportClass report, ReportQuery query) in C:\ProjetTFS\SWAP\DEV\merciera[ReHmai2015]\Sources\CCD.Tresorerie.SWAP.Reports\ReportExtensions.cs:80
CCD.Tresorerie.SWAP.Reports.ReportExtensions.SetSQLQuery(ReportClass report, List`1 queries) in C:\ProjetTFS\SWAP\DEV\merciera[ReHmai2015]\Sources\CCD.Tresorerie.SWAP.Reports\ReportExtensions.cs:70
CCD.Tresorerie.SWAP.BusinessProcessor.ReportHelper.SetReportPropertyMeta(ReportProperties reportProperty, ReportClass report) in C:\ProjetTFS\SWAP\DEV\merciera[ReHmai2015]\Sources\CCD.Tresorerie.SWAP.BusinessProcessor\ReportHelper.cs:23
CCD.Tresorerie.SWAP.App.Web.Rapports.ShowReportViewer.ShowReport(eReport reportName) in C:\ProjetTFS\SWAP\DEV\merciera[ReHmai2015]\Sources\CCD.Tresorerie.SWAP.App.Web\Rapports\ShowReportViewer.aspx.cs:646
CCD.Tresorerie.SWAP.App.Web.Rapports.ShowReportViewer.Page_Init(Object sender, EventArgs e) in C:\ProjetTFS\SWAP\DEV\merciera[ReHmai2015]\Sources\CCD.Tresorerie.SWAP.App.Web\Rapports\ShowReportViewer.aspx.cs:45
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +42
System.Web.UI.Control.OnInit(EventArgs e) +132
System.Web.UI.Page.OnInit(EventArgs e) +16
System.Web.UI.Control.InitRecursive(Control namingContainer) +143
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1477
I am feeding the dataset to the report as such :
DataSet ds = new DataSet();
ds.Tables.Add(ToDataTable<RistournesAD>(ristournes));
ds.Tables[0].TableName = "RistournesAD";
rapport.SetDataSource(ds);
It is important to denote that on the Windows server 2003 there are no errors when generating the reports in the application. All the reports that were using a stored procedure are still working perfectly fine. We rewrote a few reports to change the datasource from dataset to stored procedure and those reports begun working again.
As a temporary fix, in the IIS hosting the application we setted Enable 32-bit applications to true in the application pool. After this the reports using datasets were working properly. I would want to avoid doing this as the goal of running the application on winserver 2008 was to run them as 64bits applications.
I have looked at all the articles that I could find online and none of them were of any help. Let me know if I can provide any additional information to fix this problem.
Thank you
We have a custom built web application built on ASP (2.0 it looks like) using C#. We recently moved it from an IIS6 environment to an IIS7. We have run into an issue where a page set up to view images that had been retrieved via a search is throwing an error. The code takes a copy of the image file and puts it into a work directory renaming the copy to the user's name.
bmpList[0].Save("c:\\inetpub\\wwwroot\\SiteName\\Work\\" + ((ImageUser)Session["ImageUser"]).Username + ".TIF", info, encParams);
I know that the wwwroot is no longer a valid directory in the path so I changed it to...
bmpList[0].Save("c:\\inetpub\\SiteName\\Work\\" + ((ImageUser)Session["ImageUser"]).Username + ".TIF", info, encParams);
Saved the file, did and IIS restart and cleared my browser cache and still receive an error...
A generic error occurred in GDI+.
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.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+.
Source Error:
Line 180:
Line 181: //bmpList[0].Save("c:\\pi\\" + ((ImageUser)Session["ImageUser"]).Username + ".TIF", info, encParams);
Line 182: bmpList[0].Save("c:\\inetpub\\wwwroot\\SiteName\\Work\\" + ((ImageUser)Session["ImageUser"]).Username + ".TIF", info, encParams);
Line 183:
Line 184: for (int a = 1; a < numFiles; a++)
Source File: c:\inetpub\Sitename\SiteApp\View.aspx.cs Line: 182
Stack Trace:
[ExternalException (0x80004005): A generic error occurred in GDI+.]
System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams) +615209
View.Page_PreRender(Object sender, EventArgs e) in c:\inetpub\SiteName\SiteApp\View.aspx.cs:182
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +42
System.Web.UI.Control.OnPreRender(EventArgs e) +11056766
System.Web.UI.Control.PreRenderRecursiveInternal() +108
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3394
It seems like a fairly straightforward thing but for some reason it is not updating (the path in the error remains exactly the same). What am I missing?
Almost all the time (i.e 99.9999% of the times), when using GDI, 'a generic error occured' means that the directory you are trying to save to doesn't have the proper permissions. Typically, you need to make sure that directory is allowing asp.net to modify files. Did you check the permission on the directory you are trying to save the files to?
So oddly enough the answer is actually as simple as it looks... almost.
Changing...
c:\inetpub\wwwroot\SiteName\Work\
to...
c:\inetpub\SiteName\Work\
worked. Why it was continuing to give me the same error from the browser after I changed the code on the .cs file was that the IP that they had bound to the site still belonged to a previous version of the machine so DNS was routing me over to that box instead. All said it ended up I was on the wrong OSI model layer. I only discovered it when I went to build a test version on the same box and went to unbind the IP from the broken site and bind it to my second test site and I found that the IP I wanted wasn't an option (so it must have been manually entered). Live and learn. Thanks for the input and advise.
I have a code which allows you to download any file from server to your local host.
This code works fine when i log in as administrator but when i log in as guest user it does not let me download.. and i get an error message saying..
External component has thrown an exception.
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.Runtime.InteropServices.SEHException: External component has thrown an exception.
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.
My code is as follows
string filepath = restoredFilename.ToString();
// Create New instance of FileInfo class to get the properties of the file being downloaded
FileInfo myfile = new FileInfo(filepath);
// Checking if file exists
if (myfile.Exists)
{
// Clear the content of the response
Response.ClearContent();
// Add the file name and attachment, which will force the open/cancel/save dialog box to show, to the header
Response.AddHeader("Content-Disposition", "attachment; filename=" + myfile.Name);
//Response.AddHeader("Content-Disposition", "inline; filename=" + myfile.Name);
// Add the file size into the response header
Response.AddHeader("Content-Length", myfile.Length.ToString());
// Set the ContentType
Response.ContentType = ReturnExtension(myfile.Extension.ToLower());
//// Write the file into the response (TransmitFile is for ASP.NET 2.0. In ASP.NET 1.1 you have to use WriteFile instead)
Response.TransmitFile(myfile.FullName);
// End the response
Response.End();
}
I have to download the file using guest.. please help thanks
Stack Trace:
[SEHException (0x80004005): External component has thrown an exception.]
xyzgui.Guest.DriveContents.RestoreOneFileForGUI(Int32 machineID_Download, Int64 fileID, StringBuilder restoredFilename, UInt32 restoredFilenameBufsize) +0
xyzgui.Guest.DriveContents.file_Click(Object sender, EventArgs e) in C:\Users\jagmit\Documents\Visual Studio 2008\Projects\xyzgui\xyzgui\Guest\DriveContents.aspx.cs:341
System.Web.UI.WebControls.LinkButton.OnClick(EventArgs e) +111
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +79
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +175
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
What authentication mechanism are you using: Forms, or Windows?
Do you have impersonation turned on?
I believe that the error you are seeing is generally thrown when there's a security issue - which sounds likely when you say "when I log in as administrator".
Is there more to the method RestoreOneFileForGUI that we're not seeing - because it looks like something is throwing a security exception outside of .NET - if it was as simple as the guest account (the account the website is running under) not having access to the file path then you'd see a standard SecurityException or UnauthorizedException from the FileInfo constructor.
Here's what's going on. I'm opening a file on FTP that exists using a WebClient. The file exists and the function has worked in the past, but now for some reason throws an exception. (System.Net.WebException: The remote server returned an error: (550) File unavailable (e.g., file not found, no access).). The funny thing is, the script still opens the file and does what it's supposed to. Has anyone ever heard of anything like this?
WebClient downloadRequest = new WebClient();
downloadRequest.Credentials = new NetworkCredential(pusername, ppassword);
byte[] downloadBytes = downloadRequest.DownloadData(purl);
Here's the stack trace:
[WebException: The remote server returned an error: (550) File unavailable (e.g., file not found, no access).]
System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request) +287
System.Net.WebClient.DownloadData(Uri address) +106
System.Net.WebClient.DownloadData(String address) +29
ftp_connect.copyFile(String purl, String pusername, String ppassword, String pubordev) in d:\wwwdev\test\ftp\ftpconnect.aspx.cs:112
ftp_connect.copyFolder(String purl, String pusername, String ppassword, String pubordev) in d:\wwwdev\test\ftp\ftpconnect.aspx.cs:160
ftp_connect.Page_Load(Object sender, EventArgs e) in d:\wwwdev\test\ftp\ftpconnect.aspx.cs:93
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 includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627
Presumably the file is there from a previous successful run?
The script might be using a version of the file saved when the Web request was still working.
Maybe the file is in user by some other client/user.
It turns out that I was calling a function which called the function I was trying to get to.
So, the solution I guess was to look at the stack. Should have done that first.