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 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)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.
' Code that runs on application startup
Application.Item("appErrors") = 0
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when an unhandled error occurs
Application("appErrors") = CInt(Application("appErrors")) + 1
If CInt(Application("appErrors")) > 10 Then
' restart application
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()Only time will tell me whether this will work, but hopefully less errors will now be seen.
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
Catch ex As Exception
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.