Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > IIS7, VS2008 debug mode and Cache.Insert thread results NullReferenceException

Reply
Thread Tools

IIS7, VS2008 debug mode and Cache.Insert thread results NullReferenceException

 
 
Max2006
Guest
Posts: n/a
 
      02-22-2009

Hi,

I am debugging a very simple, web project in VS2008, IIS7. The application
uses AbsoluteExpiration timeout in Cache.Insert.

The application works fine except when a debugger is attached to it. Even a
single break point on a line of code crashes the application. The problem is
when a debugger is attached and the "onRemoveCallback" method is called,
HttpContext.Current is null.

Here is the code that reproduces the problem. If you have breakpoint
anywhere in the application, RefreshHelpContentsUrlCache method gives
NullReferenceException because HttpContext.Current is null.

Is there any way to make it work when VS2008 debugger is engaged?

Any help would be appreciated,
Max


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Caching;

namespace WebLabIIS
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = CachedData;
}
public static string CachedData
{
get
{
if (HttpContext.Current.Cache["CachedData"] == null)
RefreshCache(null, null,
CacheItemRemovedReason.Expired);

return HttpContext.Current.Cache["CachedData"] as string;
}
}
private static void RefreshCache(String key, object value,
CacheItemRemovedReason removedReason)
{
string data = "Time: " + DateTime.Now.ToString();

HttpContext.Current.Cache.Insert(
"CachedData",
data,
null,
System.DateTime.Now.AddSeconds(1),
Cache.NoSlidingExpiration,
CacheItemPriority.Default,
RefreshCache);
}
}
}


 
Reply With Quote
 
 
 
 
Allen Chen [MSFT]
Guest
Posts: n/a
 
      02-23-2009
Hi Max,

My name is Allen Chen. It's my pleasure to work with you on this issue.

I've reproduced this issue on my side. As you said, HttpContext.Current is
null in the callback method.

However, this is an expected behavior. In general, it's recommended to use
HttpRuntime.Cache instead of HttpContext.Current in the callback method.
Please check out the following documentations for more details:

http://msdn.microsoft.com/en-us/libr...40(VS.71).aspx
http://weblogs.asp.net/pjohnson/arch...06/437559.aspx

Please try it and let me know if it can solve this issue. If you have
additional questions please feel free to ask. I'll do my best to follow up.

Regards,
Allen Chen
Microsoft Online Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subs.../aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
 
 
 
Max2006
Guest
Posts: n/a
 
      02-23-2009
Thank you very much Allen. HttpRuntime.Cache solved the problem.


"Allen Chen [MSFT]" <> wrote in message
news...
> Hi Max,
>
> My name is Allen Chen. It's my pleasure to work with you on this issue.
>
> I've reproduced this issue on my side. As you said, HttpContext.Current is
> null in the callback method.
>
> However, this is an expected behavior. In general, it's recommended to use
> HttpRuntime.Cache instead of HttpContext.Current in the callback method.
> Please check out the following documentations for more details:
>
> http://msdn.microsoft.com/en-us/libr...40(VS.71).aspx
> http://weblogs.asp.net/pjohnson/arch...06/437559.aspx
>
> Please try it and let me know if it can solve this issue. If you have
> additional questions please feel free to ask. I'll do my best to follow
> up.
>
> Regards,
> Allen Chen
> Microsoft Online Support
>
> Delighting our customers is our #1 priority. We welcome your comments and
> suggestions about how we can improve the support we provide to you. Please
> feel free to let my manager know what you think of the level of service
> provided. You can send feedback directly to my manager at:
> .
>
> ==================================================
> Get notification to my posts through email? Please refer to
> http://msdn.microsoft.com/en-us/subs...#notifications.
>
> Note: MSDN Managed Newsgroup support offering is for non-urgent issues
> where an initial response from the community or a Microsoft Support
> Engineer within 2 business day is acceptable. Please note that each follow
> up response may take approximately 2 business days as the support
> professional working with you may need further investigation to reach the
> most efficient resolution. The offering is not appropriate for situations
> that require urgent, real-time or phone-based interactions. Issues of this
> nature are best handled working with a dedicated Microsoft Support
> Engineer
> by contacting Microsoft Customer Support Services (CSS) at
> http://msdn.microsoft.com/en-us/subs.../aa948874.aspx
> ==================================================
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>

 
Reply With Quote
 
Allen Chen [MSFT]
Guest
Posts: n/a
 
      02-23-2009
You're welcome Max.

Thank you for using our Newsgroup Support Service and have a nice day!

Regards,
Allen Chen
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
.
=================================================

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FormsAuthentication.SignOut() results inSystem.NullReferenceException Alex Diaz ASP .Net 0 08-22-2010 01:58 PM
netvmini.sys still not working on Windows 7 even after driver signing disabled ?! (Windows debug mode necessary for debug drivers ???) Skybuck Flying Windows 64bit 3 08-09-2009 05:54 AM
VS2008 - Localhost debug ... Michael Tissington ASP .Net 19 05-15-2008 10:52 AM
unable to compile and link application in Debug mode with library in Release mode sujeet C Programming 5 09-16-2007 05:23 PM
OutputCache results in NullReferenceException Bob ASP .Net 0 07-24-2004 03:23 PM



Advertisments