Cannot reference custom event from web.config

I wrote my own MyWebErrorEvent event, derived from WebErrorEvent , located in the App_Code folder of my ASP.NET 2.0 website project. The MyWebErrorEvent class MyWebErrorEvent not contained in the namespace. I placed the following in the web.config file:

 <configuration> <system.web> <healthMonitoring> <eventMappings> <add name="Event1" startEventCode="0" endEventCode="2147483647" type="MyWebErrorEvent"/> </eventMappings> </healthMonitoring> </system.web> </configuration> 

At compile time and runtime, I get the following error:

 Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately. Parser Error Message: Could not load type 'MyWebErrorEvent'. Source Error: Line 16: <healthMonitoring> Line 17: <eventMappings> Line 18: <add name="Event1" startEventCode="0" endEventCode="2147483647" type="MyWebErrorEvent"/> Line 19: </eventMappings> Line 20: </healthMonitoring> 

The MyWebErrorEvent class really compiles without errors. Does anyone know how to fix this?

EDIT: http://msdn.microsoft.com/en-us/library/bb398933.aspx says this should work for custom events. Quote:

Add the assembly that contains the custom implementation of the web event to the Bin subdirectory of the ASP.NET application. Alternatively, you can add the event source code file to the App_Code subdirectory.

However, he also says that this will not work for custom event providers:

Place the assembly containing the custom provider implementation in a subdirectory of the Bin application. You cannot place the supplier source code file in the App_Code subdirectory because the health monitoring system is configured and created before any code files in the App_Code subdirectory are compiled.

I assume that the documentation is actually incorrect in custom events, and they should go into a different aspect from the website.

+4
source share
3 answers

(Just guess here ...)

For websites, classes in App_Code are not compiled before execution. Your Web.config compiles before MyWebErrorEvent has the ability to dynamically compile. It is best to create a class library separate from the website and link to the project from your website. Another option is to convert to using a web application that actually compiles all types into a single DLL at compile time, rather than dynamically displaying them at runtime.

+3
source

No need to put it in a separate DLL. Use instead

type="MyWebErrorEvent,App_Code" for a reference to the MyWebErrorEvent class.

+1
source

Does your type MyWebErrorEvent use a namespace?

The error message looks like a typical problem with a missing namespace.

0
source

All Articles