Monday, February 27, 2006

Automatically restarting the Application

The Microsoft Money FAQ site is running ASP.NET 2.0, and is developed on my home machine before being manually copied across to the live site.

One curious thing that has started happening to the site, and I believe it is new to ASP.NET 2.0 in the way that it compiles code, is that I sometimes see errors like this:

Exception information:
Exception type: System.IO.FileNotFoundException
Exception message: Could not load file or assembly 'App_Web_muq0ffjm, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.


Over the last week, this error has been logged about 1000 times :-( And they always seem to start in the middle of the night, just when I won't notice....

The most annoying fact for me is that users see just error, even though the error is in the compilation of one minor component which could be safely ignored. I haven't found a solution to this apparent compilation problem, but I have now installed a workaround, so hopefully it should appear a lot less.

The basic premise is this - the Global.asax file has the following code:
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs on application startup
Application.Item("appErrors") = 0
End Sub

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when an unhandled error occurs
Application.Lock()
Application("appErrors") = CInt(Application("appErrors")) + 1
Application.UnLock()

If CInt(Application("appErrors")) > 10 Then
' restart application
rewriteConfig()
End If
End Sub
The idea is that I have a threshold (I use a setting from web.config, but have used '10' in the example above) when I reach a certain number of errors, the restart application code fires.

The code to restart the application rewrites the web.config file, which forces the application to reload. This code doesn't have to be used in the same application as the one it is restarting, which is good for additional security.
Private Sub rewriteConfig()
Try
Dim cfg As System.Configuration.Configuration
cfg = WebConfigurationManager.OpenWebConfiguration("~")

Dim compilation As CompilationSection
compilation = CType(cfg.GetSection("system.web/compilation"), CompilationSection)
If Not (compilation Is Nothing) Then

compilation.Debug = Not compilation.Debug
compilation.Debug = False
config.Save()
End If
Catch ex As Exception
End Try
End Sub
Only time will tell me whether this will work, but hopefully less errors will now be seen.

If you're having similar problems, then see if this will help you. You may need to use impersonation if your application can't write directly to the web.config file.

It would be nice to use Health Monitoring to do this for me, as that seems to me to be a 'cleaner' way of doing things, but at least this is one step on the way to reducing the occurrence of the error.

Saturday, February 25, 2006

How much will this purchase cost

The "How much will this purchase cost" tool is similar to the mini debt reduction planner - so much so, they are in the same place in Microsoft Money.

Another very simple tool which is in certain versions of Microsoft Money, but hard to find, as it is buried within the program.

This one basically gives you a guide on how much something you buy will cost, when you add in interest charges etc.

Mini Debt Reduction Planner

The Mini Debt Reduction Planner tool is a tool buried within Microsoft Money. Often I forget it is there, and so go to Excel or the Web to find one for my needs.

Simple tool within the program, difficult to track down. Hopefully more people will know about this and use the tool.


It is similar to the how much will this purchase cost tool, which is also on the same page.

The mini debt reduction planner is not a substitute for the proper debt reduction planner in the program.

New Article - "Downloaded date on the account register"

I have added a new article - Downloaded date on the account register.

This is a reasonably frequently asked question in the UK newsgroup. It relates to the display of the downloaded date in the top right corner of the account register.

In UK Versions, this is frequently not the downloaded date, but the date the statement is 'valid' from. Occasionally our banks make mistakes with the date too, and you can see a time a few hours ahead of the current time!!

The fact that it is often misleading, causes it to be a question which is often asked.