Hi all
I posted this in the MVP ASP.NET Forum but I can't seem to make my posts sho
w up in the list.
Paulo Morgado
Portugal
I'm getting the error below when truing to view the details in trace.axd.
What can this be?
Paulo Morgado
Server Error in '/worklog' Application.
----
--
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the cur
rent web request. Please review the stack trace for more information about t
he error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set t
o 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 o
bject.]
System.Web.Handlers.TraceHandler.CreateControlTable(DataTable datatable) +19
74
System.Web.Handlers.TraceHandler.ShowDetails(DataSet data) +198
System.Web.Handlers.TraceHandler.System.Web.IHttpHandler.ProcessRequest(Http
Context context) +559
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication+IExecutionSte
p.Execute() +179
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&complete
dSynchronously) +87Hi Paulo,
I have checked the stack trace, this error can be related with
CreateControlTable.
We can also find the following information for CreateControlTable:
private static System.Web.UI.WebControls.Table
CreateControlTable(System.Data.DataTable datatable)
It seems that the error message is related with the controls on your web
application.
Paulo, according to the stack trace, it is really hard for me to find out
more information. Can you help to collect some additional information?
Thanks for your effort and time.
1. Please share the sample code which will cause the NullReferenceException
on your side. I will perform more research based on the code.
2. Please let me know the .NET Framework version you installed on the
machine, 1.0 or 1.1.
We can check this information in the Add or Remove Programs in the
Control Panel.
I look forward to hearing from you soon. Have a nice day!
Regards,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Hi Paulo,
Thanks for your sharing.
To make the application run on my side, I performed the following
modifications:
1. Change the connection string in web.config:
<add key="ConnectionString" value="packet size=4096;user
id=sa;password=11111111;data source=localhost;persist security
info=False;initial catalog=Northwind" />
I also created the table "ESIAHD_TicketHistoricoVista" in the "Northwind"
database with the following columns:
HistoricoID
Date
CaseID
2. Simplified the Reperter component like following:
<asp:repeater id="ListHistoryTicket" runat="server">
<ItemTemplate>
<tr class="thf2c">
<td class="thf2c"> <%# DataBinder.Eval(Container.DataItem, "Data",
"{0:yyyy-MM-dd HH:mm:ss}") %> </td>
</tr>
</ItemTemplate>
<HeaderTemplate>
<table class='tblsize' border="0" cellpadding='0' cellspacing='1'
width="100%">
<thead>
<tr>
<th class="thf">
Data</th>
</tr>
</thead>
<tbody>
</HeaderTemplate>
<FooterTemplate>
<tfoot>
</tfoot>
</tbody></table>
</FooterTemplate>
</asp:repeater>
3. Change the code like following:
comando.CommandText = @."select HistoricoID, Data from
dbo.ESIAHD_TicketHistoricoVista where CaseID = @.CaseID";
Run the application and checked with trace.axd. Everything works fine.
Paulo, I also attached the modified sample in this message and will also
send it to you via email. Can you try to test with the modified sample
again? If there is still a problem, please try the modified sample on
another web site or on another machine. Please let me know the result.
Thanks for your effort and time!
Regards,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
Working on a Windows 2000 5.00.2195 SP2 and .NET Framework 1.1
The application is working fine. I'm having trouble only with the trace.
web.config:
<?xml version="1.0" encoding="utf-8" ?><configuration><system.web><compilati
on defaultLanguage="c#" debug="true" /><customErrors mode="RemoteOnly" defau
ltRedirect="Erro.htm" /><authentication mode="None" /><authorization><allow
users="*" /><!-- Allow all
users --></authorization><trace enabled="true" requestLimit="10" pageOutput=
"false" traceMode="SortByTime" localOnly="true" /><sessionState mode="InProc
" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data so
urce=127.0.0.1;Trusted_Conn
ection=yes"
cookieless="false" timeout="20" /><globalization requestEncoding="utf-8" res
ponseEncoding="utf-8" /></system.web><appSettings><add key="ConnectionString
" value="whatever" /></appSettings></configuration>
Xref: kermit microsoft.public.dotnet.framework.aspnet:264481
Hi Paulo,
Yes, generally speaking "Trace" is seperate from application code. However,
some times trace will also report errors when there are some issues with
the configuration or code.
According to your last information, the error does not appear on the
Windows XP machine, I suggest that we perform the following steps to
further narrow down this issue besides running the sample application:
1. Create one empty web application on the production or test server.
2. Enable Trace to the "@.Page" directive.
3. Now, please check if there is any error message when running the web
application.
4. If everything is OK, add code like following to Page_Load:
Trace.Write("test");
5. Run the web application again and check if there is any error message.
If there is any new finding, feel free to let me know. Thanks!
Regards,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Hi Paulo,
You means even a simple project will also suffer the problem on the win2k3
server ? If so, I suspect that whether the ASP.NET is correctdly installed
or is corrupted on the server machine. Would you please try reinstalling
the ASP.NET via the
"aspnet_regiis -i" in command in the vs.net commandline prompt?
For more detailed info on the aspnet_regiis tool, you may view the
following reference in MSDN:
#ASP.NET IIS Registration Tool (Aspnet_regiis.exe)
http://msdn.microsoft.com/library/e...netiisregistrat
iontoolaspnet_regiisexe.asp?frame=true
If you have any new findings, please feel free to post here. Thanks.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
Hi Paulo,
You mean after run the
aspnet_regiis -i in the commandline, all the aspx page on your machine
can't be requested(return 404 error)? If so, it doesn seems so strange.
Have you installed both .net framework1.0 and 1.1 on this machine? If so,
which version's regiis tool have you used?
the one under
F:\WINDOWS\Microsoft.NET\Framework\v1.0.3705
is for 1.0
and the one under
F:\WINDOWS\Microsoft.NET\Framework\v1.1.4322
is for 1.1
I think you can directly go to the
F:\WINDOWS\Microsoft.NET\Framework\v1.1.4322 folder and
run
aspnet_regiis -u to remove the asp.net and
then run
aspnet_regiis -i again to install and see whether it helps.
Also, since the 404 error is generally returned by IIS, I recommend that
you have a check in the IIS log to see whether it can provide any clues.
Thanks.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
Hi Paulo,
If you select "clear current trace", and then add some information to the
trace log and thow the trace details again, Can this fixed the problem?
Luke
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Showing posts with label alli. Show all posts
Showing posts with label alli. Show all posts
Saturday, March 24, 2012
Thursday, March 22, 2012
System.OutOfMemoryException: Out of memory.
Hello all
I have a ASPX file called scaleimage.aspx that scales my images down
to a given width. This page is used very much in web project I am
working on.
But due to the large size of the images I randomly get [X] images
(error) in Internet Explorer. When I open one individual image at that
point I read this exception:
[OutOfMemoryException: Out of memory.]
System.Drawing.Bitmap..ctor(String filename) +197
tekno.scaleimage.Page_Load(Object sender, EventArgs e)
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +731
Any suggestions are more than welcome. I hope you can help me.
Thank you in advance.
Regards,
Freek Versteijn
See here my code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Request("path") Is Nothing Or Request("width") Is Nothing
Then
Return
End If
Dim img As Image = New
Bitmap(Server.MapPath(Server.UrlDecode(Request("path"))))
img = resizeImage(img, Request("width"), 0)
Response.ClearHeaders()
Response.ClearContent()
Response.Clear()
Response.ContentType = "Image/JPEG"
img.Save(Response.OutputStream, Imaging.ImageFormat.Jpeg)
Response.End()
'Dispose the image object immediately to limit memory use in
case highres/large images are used
img.Dispose()
End Sub
Public Function ResizeImage(ByRef image As Image, ByVal maxWidth
As Integer, ByVal maxHeight As Integer)
Dim imgHeight, imgWidth As Double
Dim bm As Bitmap = New Bitmap(image)
imgHeight = bm.Height
imgWidth = bm.Width
If (maxWidth > 0 And imgWidth > maxWidth) Or (maxHeight > 0
And imgHeight > maxHeight) Then
'Determine what dimension is off by more
Dim deltaWidth As Double = imgWidth - maxWidth
Dim deltaHeight As Double = imgHeight - maxHeight
Dim scaleFactor As Double
'If (deltaHeight > deltaWidth) Then
'Scale by the height
'scaleFactor = maxHeight / imgHeight
'Else
' 'Scale by the Width
scaleFactor = maxWidth / imgWidth
'End If
imgWidth *= scaleFactor
imgHeight *= scaleFactor
End If
Dim w As Integer = Convert.ToInt32(imgWidth)
Dim h As Integer = Convert.ToInt32(imgHeight)
Dim inp As IntPtr = New IntPtr
Dim bmp As System.Drawing.Image = bm.GetThumbnailImage(w, h,
Nothing, inp)
Return bmp
End FunctionHi, Versteijn,
Did you try using the DrawImage method on the Graphics class instead? You
will have to change the following lines:
> Dim inp As IntPtr = New IntPtr
> Dim bmp As System.Drawing.Image = bm.GetThumbnailImage(w, h, Nothing, inp)
to:
Dim bmp As New Bitmap(w, h)
Graphics.FromImage(bmp).DrawImage(bm, w, h)
Hope this helps
Martin
Sorry, it should be another overload:
Graphics.FromImage(bmp).DrawImage(bm, 0, 0, w, h)
It is so easy with the IntelliSence...
Greetings
Martin
"Martin Dechev" <detcheff_@.hotmail.com> wrote in message news:<#uSXmc3$DHA.2660@.TK2MSFTNGP10.phx.gbl>...
> Sorry, it should be another overload:
> Graphics.FromImage(bmp).DrawImage(bm, 0, 0, w, h)
> It is so easy with the IntelliSence...
> Greetings
> Martin
Hi Martin,
Thanks, I'll try it! Why do you think this will spare memory?
Thank you.
Freek Versteijn
Hi, Freek Versteijn,
I don't know from which call the OutOfMemory originates, but I tested with a
2 MB bitmap scaling it to ~75% and it was working with the both methods. As
it is stated in the documentation for the GetThumbnailImage method it gives
good quality for 120x120, but lacks in quality for higher resolutions.
http://msdn.microsoft.com/library/e...mageTopic .asp
Greetings
Martin
"Versteijn" <versteijn@.538mail.nl> wrote in message
news:4d19834f.0403010822.54274e09@.posting.google.c om...
> "Martin Dechev" <detcheff_@.hotmail.com> wrote in message
news:<#uSXmc3$DHA.2660@.TK2MSFTNGP10.phx.gbl>...
> > Sorry, it should be another overload:
> > Graphics.FromImage(bmp).DrawImage(bm, 0, 0, w, h)
> > It is so easy with the IntelliSence...
> > Greetings
> > Martin
> Hi Martin,
> Thanks, I'll try it! Why do you think this will spare memory?
> Thank you.
> Freek Versteijn
> > Hi Martin,
> > Thanks, I'll try it! Why do you think this will spare memory?
> > Thank you.
> > Freek Versteijn
Hi Martin,
Changed my code a bit (see under), but ever call to the page uses
about 10-50 mb RAM, which is not freed after the response has been
send. After a while the process can't address any more memory.
The cause of the high memory use is the GetThumbnailImage function.
Regards,
Freek Versteijn
Here is my current code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Request("path") Is Nothing Or Request("width") Is Nothing
Then
Return
End If
Dim bmp As Bitmap = New
Bitmap(Server.MapPath(Server.UrlDecode(Request("path"))))
ResizeImage(bmp, Request("width"), 0)
Response.ClearHeaders()
Response.ClearContent()
Response.Clear()
Response.ContentType = "Image/JPEG"
bmp.Save(Response.OutputStream, Imaging.ImageFormat.Jpeg)
Response.End()
'Dispose the image object immediately to limit memory use in
case highres/large images are used
bmp.Dispose()
End Sub
Public Sub ResizeImage(ByRef bmp As Bitmap, ByVal maxWidth As
Integer, ByVal maxHeight As Integer)
Dim imgHeight, imgWidth As Double
Dim bm As Bitmap = New Bitmap(bmp)
imgHeight = bm.Height
imgWidth = bm.Width
If (maxWidth > 0 And imgWidth > maxWidth) Or (maxHeight > 0
And imgHeight > maxHeight) Then
'Determine what dimension is off by more
Dim deltaWidth As Double = imgWidth - maxWidth
Dim deltaHeight As Double = imgHeight - maxHeight
Dim scaleFactor As Double
'If (deltaHeight > deltaWidth) Then
'Scale by the height
'scaleFactor = maxHeight / imgHeight
'Else
' 'Scale by the Width
scaleFactor = maxWidth / imgWidth
'End If
imgWidth *= scaleFactor
imgHeight *= scaleFactor
End If
Dim w As Integer = Convert.ToInt32(imgWidth)
Dim h As Integer = Convert.ToInt32(imgHeight)
Dim inp As IntPtr = New IntPtr
bmp = bm.GetThumbnailImage(w, h, Nothing, inp)
End Sub
I have a ASPX file called scaleimage.aspx that scales my images down
to a given width. This page is used very much in web project I am
working on.
But due to the large size of the images I randomly get [X] images
(error) in Internet Explorer. When I open one individual image at that
point I read this exception:
[OutOfMemoryException: Out of memory.]
System.Drawing.Bitmap..ctor(String filename) +197
tekno.scaleimage.Page_Load(Object sender, EventArgs e)
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +731
Any suggestions are more than welcome. I hope you can help me.
Thank you in advance.
Regards,
Freek Versteijn
See here my code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Request("path") Is Nothing Or Request("width") Is Nothing
Then
Return
End If
Dim img As Image = New
Bitmap(Server.MapPath(Server.UrlDecode(Request("path"))))
img = resizeImage(img, Request("width"), 0)
Response.ClearHeaders()
Response.ClearContent()
Response.Clear()
Response.ContentType = "Image/JPEG"
img.Save(Response.OutputStream, Imaging.ImageFormat.Jpeg)
Response.End()
'Dispose the image object immediately to limit memory use in
case highres/large images are used
img.Dispose()
End Sub
Public Function ResizeImage(ByRef image As Image, ByVal maxWidth
As Integer, ByVal maxHeight As Integer)
Dim imgHeight, imgWidth As Double
Dim bm As Bitmap = New Bitmap(image)
imgHeight = bm.Height
imgWidth = bm.Width
If (maxWidth > 0 And imgWidth > maxWidth) Or (maxHeight > 0
And imgHeight > maxHeight) Then
'Determine what dimension is off by more
Dim deltaWidth As Double = imgWidth - maxWidth
Dim deltaHeight As Double = imgHeight - maxHeight
Dim scaleFactor As Double
'If (deltaHeight > deltaWidth) Then
'Scale by the height
'scaleFactor = maxHeight / imgHeight
'Else
' 'Scale by the Width
scaleFactor = maxWidth / imgWidth
'End If
imgWidth *= scaleFactor
imgHeight *= scaleFactor
End If
Dim w As Integer = Convert.ToInt32(imgWidth)
Dim h As Integer = Convert.ToInt32(imgHeight)
Dim inp As IntPtr = New IntPtr
Dim bmp As System.Drawing.Image = bm.GetThumbnailImage(w, h,
Nothing, inp)
Return bmp
End FunctionHi, Versteijn,
Did you try using the DrawImage method on the Graphics class instead? You
will have to change the following lines:
> Dim inp As IntPtr = New IntPtr
> Dim bmp As System.Drawing.Image = bm.GetThumbnailImage(w, h, Nothing, inp)
to:
Dim bmp As New Bitmap(w, h)
Graphics.FromImage(bmp).DrawImage(bm, w, h)
Hope this helps
Martin
Sorry, it should be another overload:
Graphics.FromImage(bmp).DrawImage(bm, 0, 0, w, h)
It is so easy with the IntelliSence...
Greetings
Martin
"Martin Dechev" <detcheff_@.hotmail.com> wrote in message news:<#uSXmc3$DHA.2660@.TK2MSFTNGP10.phx.gbl>...
> Sorry, it should be another overload:
> Graphics.FromImage(bmp).DrawImage(bm, 0, 0, w, h)
> It is so easy with the IntelliSence...
> Greetings
> Martin
Hi Martin,
Thanks, I'll try it! Why do you think this will spare memory?
Thank you.
Freek Versteijn
Hi, Freek Versteijn,
I don't know from which call the OutOfMemory originates, but I tested with a
2 MB bitmap scaling it to ~75% and it was working with the both methods. As
it is stated in the documentation for the GetThumbnailImage method it gives
good quality for 120x120, but lacks in quality for higher resolutions.
http://msdn.microsoft.com/library/e...mageTopic .asp
Greetings
Martin
"Versteijn" <versteijn@.538mail.nl> wrote in message
news:4d19834f.0403010822.54274e09@.posting.google.c om...
> "Martin Dechev" <detcheff_@.hotmail.com> wrote in message
news:<#uSXmc3$DHA.2660@.TK2MSFTNGP10.phx.gbl>...
> > Sorry, it should be another overload:
> > Graphics.FromImage(bmp).DrawImage(bm, 0, 0, w, h)
> > It is so easy with the IntelliSence...
> > Greetings
> > Martin
> Hi Martin,
> Thanks, I'll try it! Why do you think this will spare memory?
> Thank you.
> Freek Versteijn
> > Hi Martin,
> > Thanks, I'll try it! Why do you think this will spare memory?
> > Thank you.
> > Freek Versteijn
Hi Martin,
Changed my code a bit (see under), but ever call to the page uses
about 10-50 mb RAM, which is not freed after the response has been
send. After a while the process can't address any more memory.
The cause of the high memory use is the GetThumbnailImage function.
Regards,
Freek Versteijn
Here is my current code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Request("path") Is Nothing Or Request("width") Is Nothing
Then
Return
End If
Dim bmp As Bitmap = New
Bitmap(Server.MapPath(Server.UrlDecode(Request("path"))))
ResizeImage(bmp, Request("width"), 0)
Response.ClearHeaders()
Response.ClearContent()
Response.Clear()
Response.ContentType = "Image/JPEG"
bmp.Save(Response.OutputStream, Imaging.ImageFormat.Jpeg)
Response.End()
'Dispose the image object immediately to limit memory use in
case highres/large images are used
bmp.Dispose()
End Sub
Public Sub ResizeImage(ByRef bmp As Bitmap, ByVal maxWidth As
Integer, ByVal maxHeight As Integer)
Dim imgHeight, imgWidth As Double
Dim bm As Bitmap = New Bitmap(bmp)
imgHeight = bm.Height
imgWidth = bm.Width
If (maxWidth > 0 And imgWidth > maxWidth) Or (maxHeight > 0
And imgHeight > maxHeight) Then
'Determine what dimension is off by more
Dim deltaWidth As Double = imgWidth - maxWidth
Dim deltaHeight As Double = imgHeight - maxHeight
Dim scaleFactor As Double
'If (deltaHeight > deltaWidth) Then
'Scale by the height
'scaleFactor = maxHeight / imgHeight
'Else
' 'Scale by the Width
scaleFactor = maxWidth / imgWidth
'End If
imgWidth *= scaleFactor
imgHeight *= scaleFactor
End If
Dim w As Integer = Convert.ToInt32(imgWidth)
Dim h As Integer = Convert.ToInt32(imgHeight)
Dim inp As IntPtr = New IntPtr
bmp = bm.GetThumbnailImage(w, h, Nothing, inp)
End Sub
Subscribe to:
Posts (Atom)