Customizing Error Messages that Elmah Writes To the Database - asp.net

Entity Framework's DbEntityValidationException renders a message of
Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.
With a stack pointing to where the error occurred. It would be really, really useful if we could dig into the collection of errors, and write out the property and error message. Is there any way in Elmah where we can customize the output for this exception type only?

ELMAH only logs information about an error from the shared stuff on various exception. If the exception message or stacktrace doesnt contain the 'EntityValidationErrors' details, you need to save those yourself.
You can create a filter in ELMAH, implemented to check the type of the exception. If the type is DbEntityValidationException, you can dismiss that exception and raise a new one, containing a ToString of each item in the EntityValidationErrors property as the error detail.

Related

Object reference not set to an instance of an object. in asp.net with the try trans_rollback

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
public void Trans_Rollback()
{
trans.Rollback();
con.Close();
}
Looks like you disposed 'trans' or 'con' variable (or both) before calling 'TransRollback()'.
If you're using NHibernate, take a look to the querying part. If you use using statement with any of these variables you need to call your rollback method before statement parenthesis closes, since it means disposing object using were used with.
If that's not your case - provide more information, maybe at least framework you're using for accessing database. And context you calling your rollback method from.

What does the exception : "Service provider invocation failure" mean? and what is the commonly known fix for this?

I am trying to make a call for PriceQuoteService by importing new WSDL. There was an error while I tried to make the call where the auto-generated code of WSDL contained [][] instead of []. Upon making necessary replaces I am getting "Service provider invocation failure". I could not find mention of this error in all related documents.
I would like to know the cause and likely fix for this.

The EventLogWebEventProvider provider failed to log an event with the error code 0x80070057

I am writing WebEvent in my asp.net Application and it is working fine in both my development and production region.However, When I analyze Event Logs in production server for past couple of months.I see below event
The following exception was thrown by the web event provider 'EventLogProvider' in the application '/(MyApplicationName)' (in an application lifetime a maximum of one exception will be logged per provider instance):
System.Web.HttpException (0x80004005): The EventLogWebEventProvider provider failed to log an event with the error code 0x80070057.
at System.Web.Management.EventLogWebEventProvider.ProcessEvent(WebBaseEvent eventRaised)
at System.Web.Management.WebBaseEvent.RaiseInternal(WebBaseEvent eventRaised, ArrayList firingRuleInfos, Int32 index0, Int32 index1)
Although Occurrence is very low, still I am curious to understand why this is happening.I tried to do some research and found below link
http://forums.iis.net/t/1201176.aspx?IIS+Keep+hanging
According to this link, I may be passing some invalid argument while writing event log.
But I double checked my EventLog.WriteEntry method and I am using it in my application only in couple of places and moreover, I am passing static string message. If argument is invalid then it should occur every time I try to write event.
Can anyone please help me understanding possible cause for this event.is there any known issue when working with EvenLog?
Check your code you may be trying to perform an invalid operation.
In my case i was writing a file to C Drive after changing Location to D Drive Problem Resolved

Me.ChangeSet.GetOriginal, Object reference not set to an instance of an object

hey , I have a problem with updating a record using a domain service, entity framework and asp.net.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 257: }
Line 258: Me.ObjectContext.OrderStatusHistories.AddObject(_orderStatusHistory)
Line 259: Me.ObjectContext.Orders.AttachAsModified(currentOrder, Me.ChangeSet.GetOriginal(currentOrder))
Line 260: End Sub
Line 261:
The order is commited in the database, does anyone know whats going on here?
Turns out the changeset was null. So in my code added an if changeset is not null, i dont need to run the code if there isnt a changeset.

Saving error message and stack on asp.net

I've designed a website that works through my own PC.
I set the IIS to work with Custom Errors in case user ran into some unknown exception.
I've also added a check that the error page will e-mail me whenever it found an error.
Can I somehow get the error information (Stack and description) from the error page?
I encourages you to use Open Source library out there that provided functional need. My recommendation is ELMAH.
With a few line of settings in your web.config, you will all set. result screen looks like this.
(source: googlecode.com)
You can use ASP.NET Health monitoring.
http://msdn.microsoft.com/en-us/library/ms998306.aspx
Catch any errors that might be thrown and write them to the event log.
EventLog Logger = new EventLog();
Logger.Source = "ApplictionNme";
Logger.WriteEntry("Writing to event log.");

Resources