Skip to content

In IIS integrated mode Elmah fails at application start (Can't access HttpContext.Current.Request)#17

Merged
mythz merged 1 commit into
ServiceStackV3:masterfrom
AkosLukacs:master
May 22, 2013
Merged

In IIS integrated mode Elmah fails at application start (Can't access HttpContext.Current.Request)#17
mythz merged 1 commit into
ServiceStackV3:masterfrom
AkosLukacs:master

Conversation

@AkosLukacs

Copy link
Copy Markdown
Contributor

A workaround is described here: http://stackoverflow.com/a/2196594/618331
Just wrapped the normal Elmah log statements in try-catch and added the workaround Elmah log statements in the catch{} blocks.

Can't create a real test for it, because it happens only at Application_start...
A dummy global.asax.cs:

protected void Application_Start()
{
  try {
    //do something...
  }
  catch(Exception exc) {
    //try logging
    logger.Error("something went wrong...", exc); //this is line 50
  }
}

The exception:

System.Web.HttpException (0x80004005): Request is not available in this context
   at System.Web.HttpContext.get_Request()
   at Elmah.ErrorLog.InferApplicationName(HttpContext context)
   at Elmah.ErrorLog.GetDefaultImpl(HttpContext context)
   at Elmah.ServiceContainer.GetService(Type serviceType)
   at Elmah.ErrorLog.GetDefault(HttpContext context)
   at ServiceStack.Logging.Elmah.ElmahInterceptingLogger.Error(Object message)
   at x.Application_Start() in x\Global.asax.cs:line 50

Also had to update Nuget.exe because
The schema version of 'NLog' is incompatible with version 1.6.21205.9031 of NuGet. Please upgrade NuGet to the latest version from http://go.microsoft.com/fwlink/?LinkId=213942.

… HttpContext.Current.Request)

A workaround is described here: http://stackoverflow.com/a/2196594/618331
Just wrapped the normal Elmah log statements in try-catch and added the workaround Elmah log statements in the catch{} blocks.

Can't create a real test for it, because it happens only at Application_start...
A dummy global.asax.cs:

protected void Application_Start()
{
  try {
    //do something...
  }
  catch(Exception exc) {
    //try logging
    logger.Error("something went wrong...", exc); //this is line 50
  }
}

The exception:

System.Web.HttpException (0x80004005): Request is not available in this context
   at System.Web.HttpContext.get_Request()
   at Elmah.ErrorLog.InferApplicationName(HttpContext context)
   at Elmah.ErrorLog.GetDefaultImpl(HttpContext context)
   at Elmah.ServiceContainer.GetService(Type serviceType)
   at Elmah.ErrorLog.GetDefault(HttpContext context)
   at ServiceStack.Logging.Elmah.ElmahInterceptingLogger.Error(Object message)
   at x.Application_Start() in x\Global.asax.cs:line 50

Also had to update Nuget.exe because
   The schema version of 'NLog' is incompatible with version 1.6.21205.9031 of NuGet. Please upgrade NuGet to the latest version from http://go.microsoft.com/fwlink/?LinkId=213942.
mythz added a commit that referenced this pull request May 22, 2013
In IIS integrated mode Elmah fails at application start (Can't access HttpContext.Current.Request)
@mythz mythz merged commit caefef7 into ServiceStackV3:master May 22, 2013
@mythz

mythz commented May 22, 2013

Copy link
Copy Markdown
Contributor

k kool thx.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants