My Event Viewer keeps logging a NullReferenceException every so many minutes and the offending line is "ImageFetch.ashx?Size=2&ImageID=11". I looked at the code all day long up and down and cant seem to find anything that I know of. Anybody have any
suggestions?
Here is the ImageFetch.ashx (It's pretty much straight from the "ClubSite" starter kit.
I dont recall adjusting anything here. I just took the pieces and parts and learned from them.
Well, seeing your handler code, it seems to be alright. First thing I would suggest you to do is to use breakpoint in your ProcessRequest method. And make sure you are passing right parameter to HttpContext to ProcessRequest. Secondly, it could be because
you are giving sort of rights to the method 'writeSingleImage' to write stream rather 'ProcessRequest' doing it. It might do not permit to write stream. So, try doing this:
Its has been awhile since I worked with the club starter kit, but it sounds like you have a photo(id=11) linked to an event. I believe one of the problems with this was that if you delete a photo it does not clear that link in the event, therefore when
the event tries to load in the events list or default page you will get a null error.
Check your images table and make sure you have a photo with an Id of 11, if not go into events table and clear the photo column, if you cannot clear it give it a valid id.
Sal
Member
4 Points
12 Posts
ImageFetch.ashx?Size=2&ImageID=11
Sep 22, 2009 08:49 PM|LINK
My Event Viewer keeps logging a NullReferenceException every so many minutes and the offending line is "ImageFetch.ashx?Size=2&ImageID=11". I looked at the code all day long up and down and cant seem to find anything that I know of. Anybody have any suggestions?
Null Reference Exception NullReferenceException ImageFetch ImageFetch.ashx
saad ahmed k...
Member
104 Points
63 Posts
Re: ImageFetch.ashx?Size=2&ImageID=11
Sep 22, 2009 09:09 PM|LINK
Could you provide relevant code your trying in ImageFetch.ashx handler class?
Sal
Member
4 Points
12 Posts
Re: ImageFetch.ashx?Size=2&ImageID=11
Sep 22, 2009 09:55 PM|LINK
Here is the SqlDataSource:
Event Viewer Message:
Event code: 3005
Event message: An unhandled exception has occurred.
Event time: 9/22/2009 4:35:14 PM
Event time (UTC): 9/22/2009 9:35:14 PM
Event ID: 9f2e25c17fd240e284185d11722f523a
Event sequence: 1777
Event occurrence: 17
Event detail code: 0
Application information:
Application domain: /LM/W3SVC/1/ROOT-85-128981282593510557
Trust level: Full
Application Virtual Path: /
Application Path: e:\Inetpub\wwwroot\
Machine name: MYWEBSERVER
Process information:
Process ID: 4144
Process name: w3wp.exe
Account name: NT AUTHORITY\NETWORK SERVICE
Exception information:
Exception type: NullReferenceException
Exception message: Object reference not set to an instance of an object.
Request information:
Request URL: http://www.mywebsite.com/ImageFetch.ashx?Size=2&ImageID=19
Request path: /ImageFetch.ashx
User host address: xxx.xxx.xxx.xxx
User:
Is authenticated: False
Authentication Type:
Thread account name: NT AUTHORITY\NETWORK SERVICE
Thread information:
Thread ID: 7
Thread account name: NT AUTHORITY\NETWORK SERVICE
Is impersonating: False
Stack trace: at ImageFetch.writeSingleImage(Int32 ImageID, Int32 size, Stream output)
at ImageFetch.ProcessRequest(HttpContext context)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
prashkumar22
Participant
1416 Points
228 Posts
Re: ImageFetch.ashx?Size=2&ImageID=11
Sep 22, 2009 10:09 PM|LINK
Seeing your ImageFetch.ashx handler would be helpful , can you post that?
Also try keeping a breakpoint in the handler and make sure you are not getting null values whereever you need it.
looking at the error log there seems to a error at this method
ImageFetch.writeSingleImage()
Sal
Member
4 Points
12 Posts
Re: ImageFetch.ashx?Size=2&ImageID=11
Sep 22, 2009 11:14 PM|LINK
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Here is the ImageFetch.ashx (It's pretty much straight from the "ClubSite" starter kit.
I dont recall adjusting anything here. I just took the pieces and parts and learned from them.
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ImageFetch.ashx
<%@ WebHandler Language="C#" Class="ImageFetch" %> using System; using System.Web; using System.Data.SqlClient; using System.Data; using System.IO; public class ImageFetch : IHttpHandler { const int BUFFERSIZE = 1024; public bool IsReusable { get { return true; } } public void ProcessRequest(HttpContext context) { HttpResponse response = context.Response; HttpRequest request = context.Request; response.ContentType = "image/jpeg"; response.Cache.SetCacheability(HttpCacheability.Public); response.BufferOutput = false; writeSingleImage(Convert.ToInt32(request.QueryString["ImageID"]), Convert.ToInt32(request.QueryString["Size"]), response.OutputStream); response.End(); } public void writeSingleImage(int ImageID, int size, Stream output) { string cxnstr = System.Configuration.ConfigurationManager.ConnectionStrings["NewsCenterConnectionString"].ConnectionString; SqlConnection connection = new SqlConnection(cxnstr); string query; if (size == 0) { query = "select largeimage from images where id=@item_id"; } else if (size == 1) { query = "select thumbimage from images where id=@item_id"; } else if (size == 2) { query = "select origimage from images where id=@item_id"; } else { query = "select largeimage from images where id=@item_id"; } SqlCommand command = new SqlCommand(query, connection); SqlParameter param0 = new SqlParameter("@item_id", SqlDbType.Int); param0.Value = ImageID; command.Parameters.Add(param0); connection.Open(); byte[] d = ((byte[])(command.ExecuteScalar())); output.Write(d, 0, d.Length); connection.Close(); } }XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Here is the ImageThumbnail.ascx
The only thing I did here was comment out the last line which I cant imagine it causing the problem.
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
<%@ Control Language="C#" ClassName="ImageThumbnail" %> <script runat="server"> public object PhotoID { get { object o = ViewState["PhotoID"]; return (o != null) ? (int)o : 0; } set { ViewState["PhotoID"] = (value != null && value !=DBNull.Value) ? Convert.ToInt32(value) : 0; } } public ImageSizes ImageSize { get { object o = ViewState["ImageSize"]; return (o != null) ? (ImageSizes)o : ImageSizes.Thumb; } set { ViewState["ImageSize"] = value; } } public enum ImageSizes { Large = 0, Thumb = 1, FullSize = 2 } public string NoPhotoImg { get { object o = ViewState["NoPhotoImg"]; return (o != null) ? (string)o : null; } set { ViewState["NoPhotoImg"] = value; } } protected void Page_PreRender(object sender, System.EventArgs e) { if (Convert.ToInt32(PhotoID) == 0) { if (NoPhotoImg != null) { Image1.ImageUrl = NoPhotoImg; } else { Image1.Visible = false; } } else { Image1.ImageUrl = "ImageFetch.ashx?Size=" + Convert.ToInt32(ImageSize) + "&ImageID=" + Convert.ToString(PhotoID); } } </script> <asp:Image ID="Image1" runat="server" CssClass="photo" /> <%--<asp:Image ID="Image1" runat="server" CssClass="photo" BorderWidth="1" />--%>saad ahmed k...
Member
104 Points
63 Posts
Re: ImageFetch.ashx?Size=2&ImageID=11
Sep 23, 2009 10:32 AM|LINK
Well, seeing your handler code, it seems to be alright. First thing I would suggest you to do is to use breakpoint in your ProcessRequest method. And make sure you are passing right parameter to HttpContext to ProcessRequest. Secondly, it could be because you are giving sort of rights to the method 'writeSingleImage' to write stream rather 'ProcessRequest' doing it. It might do not permit to write stream. So, try doing this:
<div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">Bitmap newBmp = ConvertToBitmap(ShowEmpImage((long)Convert.ToInt32(ImageId)));</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> if (newBmp != null)</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> {</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> newBmp.Save(context.Response.OutputStream, ImageFormat.Jpeg);</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> newBmp.Dispose();</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">public void ProcessRequest(HttpContext context) { // Retrieve ImageId id etc Bitmap newBmp = ConvertToBitmap(ShowEmpImage((long)Convert.ToInt32(ImageId))); if (newBmp != null) { newBmp.Save(context.Response.OutputStream, ImageFormat.Jpeg); newBmp.Dispose(); } } // Convert byte array to Bitmap (byte[] to Bitmap) protected Bitmap ConvertToBitmap(byte[] bmp) { if (bmp != null) { TypeConverter tc = TypeDescriptor.GetConverter(typeof(Bitmap)); Bitmap b = (Bitmap)tc.ConvertFrom(bmp); return b; } return null; } public byte[] ShowEmpImage(long ImageId) { // Get Bytes[] from database. return Pic; }}</div>
public void ProcessRequest(HttpContext context) { // Retrieve ImageId id etc Bitmap newBmp = ConvertToBitmap(ShowEmpImage((long)Convert.ToInt32(ImageId))); if (newBmp != null) { newBmp.Save(context.Response.OutputStream, ImageFormat.Jpeg); newBmp.Dispose(); } } // Convert byte array to Bitmap (byte[] to Bitmap) protected Bitmap ConvertToBitmap(byte[] bmp) { if (bmp != null) { TypeConverter tc = TypeDescriptor.GetConverter(typeof(Bitmap)); Bitmap b = (Bitmap)tc.ConvertFrom(bmp); return b; } return null; } public byte[] ShowEmpImage(long ImageId) { // Get Bytes[] from database. return Pic; }swatiarora34...
Member
292 Points
59 Posts
Re: ImageFetch.ashx?Size=2&ImageID=11
Sep 23, 2009 10:41 AM|LINK
Hi,
I think you have not declared your Image Handler in web.config.
<add verb="*" path="" type=""/>
and if you have declared then check the path and type of the same.
MaineOne
Contributor
2087 Points
469 Posts
Re: ImageFetch.ashx?Size=2&ImageID=11
Oct 03, 2009 06:59 PM|LINK
Its has been awhile since I worked with the club starter kit, but it sounds like you have a photo(id=11) linked to an event. I believe one of the problems with this was that if you delete a photo it does not clear that link in the event, therefore when the event tries to load in the events list or default page you will get a null error.
Check your images table and make sure you have a photo with an Id of 11, if not go into events table and clear the photo column, if you cannot clear it give it a valid id.