ywuwgij / elmah

Automatically exported from code.google.com/p/elmah
Apache License 2.0
0 stars 0 forks source link

InvalidCastException in ErrorFilterModule.cs (Line 67) under high trust #13

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Starting my website with ASP.NET Development Server
2. Before site is shown, Exception is thrown in ErrorFilterModule.cs, 
Line67

What is the expected output? What do you see instead?
Exception: Cannot convert string to IHttpModule

What version of the product are you using? On what operating system?
ELMAH 1.0.8922, BETA 1

Problem:
foreach (IHttpModule module in HttpModuleRegistry.GetModules(application)) 
didn't work. Seems to be a NameValueCollections which is returned. 

I had changed it to: 

     HttpModuleCollection modules = (HttpModuleCollection) 
HttpModuleRegistry.GetModules(application); 

     foreach (string moduleName in modules) 
     { 
       IExceptionFiltering filtering = modules[moduleName] as 
IExceptionFiltering; 

Original issue reported on code.google.com by schoenho...@gmail.com on 2 Jul 2007 at 10:36

Attachments:

GoogleCodeExporter commented 9 years ago
Reproduced in 1.0 BETA 1a (build 1.0.8925.0) as well. The exception thrown is:

[InvalidCastException: Unable to cast object of type 'System.String' to 
type 'System.Web.IHttpModule'.]
   Elmah.ErrorFilterModule.Init(HttpApplication application) in 
C:\Projects\Public\ELMAH\src\Elmah\ErrorFilterModule.cs:66
   System.Web.HttpApplication.InitModules() +267
   System.Web.HttpApplication.InitInternal(HttpContext context, HttpApplicationState 
state, MethodInfo[] handlers) +1251
   System.Web.HttpApplicationFactory.GetNormalApplicationInstance(HttpContext 
context) +243
   System.Web.HttpApplicationFactory.GetApplicationInstance(HttpContext context) +106
   System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +317

Original comment by azizatif on 3 Jul 2007 at 7:06

GoogleCodeExporter commented 9 years ago
Fixed summary to be more accurate.

Original comment by azizatif on 3 Jul 2007 at 7:07

GoogleCodeExporter commented 9 years ago
This exception occurs only when trust level is high or full.

Original comment by azizatif on 3 Jul 2007 at 7:10

GoogleCodeExporter commented 9 years ago
The InvalidCastException was caused by returning HttpApplication.Modules 
directly 
under high trust. The enumerator of the returned collection 
(HttpModuleCollection) 
yields keys rather than IHttpModule objects, thus causing an 
InvalidCastException 
when the called would try to access the collection elements as IHttpModule 
objects.

Original comment by azizatif on 3 Jul 2007 at 7:24

GoogleCodeExporter commented 9 years ago
Added new patch because the original one attached with the issue is invalid.

Original comment by azizatif on 3 Jul 2007 at 7:37

Attachments: