Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read stack trace or error info generated in .Net program to find root cause of exception

Tags:

c#

exception

This is really basic question and may be duplicate. Can anyone tell me how useful error info generated by any program in .Net.

Today I got an error "Ambiguous match found." while saving entity in database (using EF4) I can't figure out why this error is coming, what is the root cause. Attached is the snap for same.

alt text Here is the complete Error Details,

System.Reflection.AmbiguousMatchException was unhandled by user code
     Message=Ambiguous match found.
     Source=mscorlib
     StackTrace:
   at System.RuntimeType.GetPropertyImpl(String name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers)
   at System.Type.GetProperty(String name)
   at IAA.Data.EntityFramework.RepositoryWithTypedId`2.SaveOrUpdate[T](T entity)
   at ABC.XYZ.ApplicationServices.AcknowledgementManagementService.SaveOrUpdate(AcknowledgementFormViewModel acknowledgementFormViewModel) in E:\RA\ABC.XYZ\app\ABC.XYZ.ApplicationServices\AcknowledgementManagementService.cs:line 123
   at ABC.XYZ.Web.Controllers.AcknowledgementsController.Acknowledgements(AcknowledgementFormViewModel acknowledgementFormViewModel) in E:\RA\ABC.XYZ\app\ABC.XYZ.Web.Controllers\AcknowledgementsController.cs:line 68
   at lambda_method(Closure , ControllerBase , Object[] )
   at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
   at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClassd.<InvokeActionMethodWithFilters>b__a()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)

InnerException:

like image 459
indiPy Avatar asked Dec 28 '22 04:12

indiPy


2 Answers

This means that an System.Reflection.AmbiguousMatchException was thrown, and was not handled. It was thrown at System.RuntimeType.GetPropertyImpl(String name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers), which was called from System.Type.GetProperty(String name), which was called from IAA.Data.EntityFramework.RepositoryWithTypedId2.SaveOrUpdate[T](T entity)`,

etc.

like image 182
John Saunders Avatar answered Dec 30 '22 17:12

John Saunders


Hmya, no such luck. It would be very nice indeed if the Type.GetProperty() method would actually say which name was ambiguous. But it doesn't and you cannot easily find out. The code lives in the .NET framework and it is optimized, the debugger cannot retrieve the value of the name argument. Your only cue is that your entity model has two properties with the same name. Something like that anyway.

like image 43
Hans Passant Avatar answered Dec 30 '22 17:12

Hans Passant