I have a .NET 4.0 web application which implements an error handler within the Application_Error event of Global.asax.
When an exception occurs this intercepts it and sends me an email including a variety of information like the logged in user, the page the error occurred on, the contents of the session etc.
This is all great but there is some fundamental detail missing which I seem unable to locate.
For instance, this is a subset of an error I would receive and the associated stack trace:
Source: Telerik.Web.UI
Message: Selection out of range
Parameter name: value
Stack trace: at Telerik.Web.UI.RadComboBox.PerformDataBinding(IEnumerable dataSource)
at Telerik.Web.UI.RadComboBox.OnDataSourceViewSelectCallback(IEnumerable data)
at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback)
at Telerik.Web.UI.RadComboBox.OnDataBinding(EventArgs e)
at Telerik.Web.UI.RadComboBox.PerformSelect()
at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
at Telerik.Web.UI.RadComboBox.DataBind()
at System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound()
at Telerik.Web.UI.RadComboBox.OnPreRender(EventArgs e)
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Now as lovely as this is I could do with knowing a) the name of the control and b) the value which caused the control to be 'out of range'.
Any suggestions about how I could get this sort of information? I've run this in debug mode and the objects passed to Global.asax don't seem to hold any more detail that I can see.
Ship your PDBs along with your assemblies. This way you will get line numbers and source code filenames in your exception stack trace. And once you have line numbers you know what code you have written on that line.
I was unable to fulfil my requirement without implementing some custom code.
I have now added some code within the MasterPage that stores __EVENTTARGET and __EVENTARGUMENT parameters upon every postback. These are cleared whenever there is a fresh page load. If an error occurs, these values form part of the debug email which allow us to get an understanding of what the user was doing when the error occurred.
You can show such exception as follows
try
{
}
catch(Exception ex)
{
Response.Write("Source: " + ex.Source);
Response.Write("Message: " + ex.Message);
Response.Write("Stack Trace: " + ex.StackTrace);
}
Related
I have an asp.net application in which I am receiving the following error message: -
Exception: System.Reflection.TargetInvocationException
Message: Exception has been thrown by the target of an invocation.
Stack Trace:
at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Web.UI.WebControls.ObjectDataSourceView.InvokeMethod(ObjectDataSourceMethod method, Boolean disposeInstance, Object& instance)
at System.Web.UI.WebControls.ObjectDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments)
at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback)
at System.Web.UI.WebControls.DataBoundControl.PerformSelect()
at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
at System.Web.UI.WebControls.FormView.DataBind()
at System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound()
at System.Web.UI.WebControls.FormView.EnsureDataBound()
at System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls()
at System.Web.UI.Control.EnsureChildControls()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
In an effort to debug the error I have turned the EnablePartialRendering setting to false but this didn't help and the error was displayed in exactly the same way.
The only clue I have is that in the Output window for Debug I am seeing this message: -
'A first chance exception of type 'System.InvalidCastException' occurred in App_Code.iqmc5gba.dll'
Whilst this indicates that the error is occurring within the code held in the App_Code folder I'm actually none the wiser as there are 211 files that would appear to be contributing to the content of the dll as they are all named App_Code.iqmc5gba.nnn.cs where nnn is a number between 0 and 210
At the time ther error occurs the code is getting the data to display a record in a formview. The error only occurs on one record in the database that I can see at the moment.
Is anyone aware of any techniques that I can use to try and identify the line of code that is being executed at the point the invalidcastexception is encountered?
This typically happens when reading data (using a datareader, for example) and certain column comes back null when you actually expect it to have at least some value. Consider this code:
int age = (int)reader["age"]; //will throw ClassCastException if null
If for some reason the result set contains a null value on the age column, the value held by reader["age"] will not be an integer but rather a DBNull.Value which is a different type; hence the ClassCastException.
If you don't have access to the source code, your best bet is to make compare a good record with the bad one and make sure that corresponding columns on both records have values.
I was having the same issues. Not sure if you have fixed your problem but Icarus is on the correct path. What I found was that in some cases you need to set the security question for an account to be created. I solved the problem by opening the ASP.Net Config under the Project Tab in VS2012. Click on the Provider Tab and Select a Provider for site management (Single in my case). Once that is active and you test the connection, when you go back to add a new user, there will be an option to enter a security question and answer. This seems to fix the problem.
I have a problem configuring multiple hostnames in Composite C1.
Background:
I have two websites in C1: site1 and site2. The C1 installation is mainly for site1 and works with the host www.site1.com (and alias site1.com).
Now I've added another site, site2, to C1. When browsing to site1.com/site2 I end up on the site2 website. All fine. Then I try to add another hostname, www.site2.com, to URL Configuration -> Hostnames. After adding www.site2.com and browsing to www.site2.com I get the following exception: "Item has already been added. Key in dictionary: '' Key being added: ''"
The stacktrace looks as follows:
[ArgumentException: Item has already been added. Key in dictionary: '' Key being added: '']
System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add) +9353115
System.Collections.Hashtable.Add(Object key, Object value) +11
Composite.Core.Collections.Generic.Hashtable`2.Add(TKey key, TValue value) +105
Composite.Plugins.Routing.Pages.PageUrlBuilder.BuildUrlSet(IPage page, Guid parentPageId) +1935
Composite.Core.WebClient.Renderings.Page.PageStructureInfo.BuildFolderPaths(SitemapBuildingData pagesData, IEnumerable`1 elements, IDictionary`2 urlToIdLookup, IPageUrlBuilder builder) +253
Composite.Core.WebClient.Renderings.Page.PageStructureInfo.BuildMap(UrlSpace urlSpace) +2200
Composite.Core.WebClient.Renderings.Page.PageStructureInfo.GetMap(PublicationScope publicationScope, CultureInfo localizationScope, UrlSpace urlSpace) +482
Composite.Core.WebClient.Renderings.Page.PageStructureInfo.GetPageUrlBuilder(PublicationScope publicationScope, CultureInfo localizationScope, UrlSpace urlSpace) +9
Composite.Plugins.Routing.Pages.DefaultPageUrlProvider.ParseUrl(String relativeUrl, UrlSpace urlSpace, UrlKind& urlKind) +311 Composite.Plugins.Routing.Pages.DefaultPageUrlProvider.ParseUrl(String absoluteUrl, UrlKind& urlKind) +306 Composite.Core.Routing.Pages.C1PageRoute.GetRouteData(HttpContextBase context) +156
System.Web.Routing.RouteCollection.GetRouteData(HttpContextBase httpContext) +287
System.Web.Routing.UrlRoutingModule.PostResolveRequestCache(HttpContextBase context) +60
System.Web.Routing.UrlRoutingModule.OnApplicationPostResolveRequestCache(Object sender, EventArgs e) +86
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +148
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
Does anyone have a solution for this?
Thanks in advance...
UPDATE:
After changing the dll suggested by Dmitry Dzygin I get the following stack trace:
[ArgumentException: Item has already been added. Key in dictionary: '' Key being added: '']
System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add) +9353115
System.Collections.Hashtable.Add(Object key, Object value) +11
Composite.Core.Collections.Generic.Hashtable`2.Add(TKey key, TValue value) in c:\Builds\1\Freja\CodeplexBuild\Sources\Public\Composite\Core\Collections\Generic\Hashtable.cs:28
Composite.Plugins.Routing.Pages.PageUrlBuilder.BuildUrlSet(IPage page, Guid parentPageId) in c:\Builds\1\Freja\CodeplexBuild\Sources\Public\Composite\Plugins\Routing\Pages\PageUrlBuilder.cs:190
Composite.Core.WebClient.Renderings.Page.PageStructureInfo.BuildFolderPaths(SitemapBuildingData pagesData, IEnumerable`1 elements, IDictionary`2 urlToIdLookup, IPageUrlBuilder builder) in c:\Builds\1\Freja\CodeplexBuild\Sources\Public\Composite\Core\WebClient\Renderings\Page\PageStructureInfo.cs:630
Composite.Core.WebClient.Renderings.Page.PageStructureInfo.BuildFolderPaths(SitemapBuildingData pagesData, IEnumerable`1 roots, IPageUrlBuilder pageUrlBuilder, IDictionary`2 urlToIdLookup) in c:\Builds\1\Freja\CodeplexBuild\Sources\Public\Composite\Core\WebClient\Renderings\Page\PageStructureInfo.cs:612
Composite.Core.WebClient.Renderings.Page.PageStructureInfo.BuildMap(UrlSpace urlSpace) in c:\Builds\1\Freja\CodeplexBuild\Sources\Public\Composite\Core\WebClient\Renderings\Page\PageStructureInfo.cs:559
Composite.Core.WebClient.Renderings.Page.PageStructureInfo.GetMap(PublicationScope publicationScope, CultureInfo localizationScope, UrlSpace urlSpace) in c:\Builds\1\Freja\CodeplexBuild\Sources\Public\Composite\Core\WebClient\Renderings\Page\PageStructureInfo.cs:277
Composite.Core.WebClient.Renderings.Page.PageStructureInfo.GetPageUrlBuilder(PublicationScope publicationScope, CultureInfo localizationScope, UrlSpace urlSpace) in c:\Builds\1\Freja\CodeplexBuild\Sources\Public\Composite\Core\WebClient\Renderings\Page\PageStructureInfo.cs:342
Composite.Plugins.Routing.Pages.DefaultPageUrlProvider.ParseUrl(String relativeUrl, UrlSpace urlSpace, UrlKind& urlKind) in c:\Builds\1\Freja\CodeplexBuild\Sources\Public\Composite\Plugins\Routing\Pages\DefaultPageUrlProvider.cs:249
Composite.Plugins.Routing.Pages.DefaultPageUrlProvider.ParseUrl(String absoluteUrl, UrlKind& urlKind) in c:\Builds\1\Freja\CodeplexBuild\Sources\Public\Composite\Plugins\Routing\Pages\DefaultPageUrlProvider.cs:206
Composite.Core.Routing.Pages.C1PageRoute.GetRouteData(HttpContextBase context) in c:\Builds\1\Freja\CodeplexBuild\Sources\Public\Composite\Core\Routing\Pages\C1PageRoute.cs:90
System.Web.Routing.RouteCollection.GetRouteData(HttpContextBase httpContext) +287
System.Web.Routing.UrlRoutingModule.PostResolveRequestCache(HttpContextBase context) +60
System.Web.Routing.UrlRoutingModule.OnApplicationPostResolveRequestCache(Object sender, EventArgs e) +86
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +148
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
Looks like some of kind of a url collision when 2 C1 pages received the same url or something like that. As a solution I recommend you to copy debug version Composite.dll file and Composite.pdf files to the /bin folder of your website. You can find those at Codeplex in "Other available downloads section" of the release page ( http://compositec1.codeplex.com/releases/view/80764 ) After that you will see the exact line in the code that caused it. Once you have it, I'll be able to either fix it or to add some code assertions/validation logic.
Update.
Looking through code it appears that the exception is possible only if you have 2 websites with empty "UrlTitle" field. Normally there's validation logic that prevents this situation from happenning. Try to edit both website's roots, give them not empty "Url Title" fields, and publish them afterwards, that should solve the issue. If the bug is still persists, I either need a better repro (I failed to reproduce it with the provided one), or if you send me a copy of a website, I'll debug it.
Can any one explain this exception?
Server Error in '/eims_web' Application:
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:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace) +24
System.Xml.XmlDocument.Load(XmlReader reader) +108
System.Web.UI.WebControls.XmlDataSource.PopulateXmlDocument(XmlDocument document, CacheDependency& dataCacheDependency, CacheDependency& transformCacheDependency) +342
System.Web.UI.WebControls.XmlDataSource.GetXmlDocument() +253
System.Web.UI.WebControls.XmlHierarchicalDataSourceView.Select() +51
System.Web.UI.WebControls.Menu.DataBindItem(MenuItem item) +326
System.Web.UI.WebControls.Menu.PerformDataBinding() +99
System.Web.UI.WebControls.HierarchicalDataBoundControl.PerformSelect() +126
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +125
System.Web.UI.WebControls.Menu.DataBind() +29
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +104
System.Web.UI.WebControls.Menu.EnsureDataBound() +70
System.Web.UI.WebControls.BaseDataBoundControl.OnPreRender(EventArgs e) +43
System.Web.UI.WebControls.Menu.OnPreRender(EventArgs e, Boolean registerScript) +89
System.Web.UI.WebControls.Menu.OnPreRender(EventArgs e) +63
System.Web.UI.Control.PreRenderRecursiveInternal() +200
System.Web.UI.Control.PreRenderRecursiveInternal() +322
System.Web.UI.Control.PreRenderRecursiveInternal() +322
System.Web.UI.Control.PreRenderRecursiveInternal() +322
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4837
Without seeing your code it is going to be hard to say, but by the looks of the stack trace, I will wager a guess and say you have a TreeView/Menu bound to an XmlDataSource.
Clearly something is going wrong during the databinding process, but again without seeing your code that populates the XmlDataSource it is going to be next to impossible to assist you further.
The XmlReader instance passed from XmlDocument.Load to XmlLoader.Load is null, which means that XmlDataSource.PopulateXmlDocument passes a null reader to XmlDocument.Load, which occurs when XmlDataSource.GetReader returns null.
The only code path where this happens requires that XmlDataSource.DataFile is null or empty and XmlDataSource.Data is either null, empty or costs of only white-space characters.
I have health monitoring turned on, and i have the following error i'm trying to understand:
Exception:
Exception information:
Exception type: System.InvalidCastException
Exception message: Specified cast is not valid.
Thread information:
Thread ID: 5
Thread account name: NT AUTHORITY\NETWORK SERVICE
Is impersonating: False
Stack trace: at _Default.Repeater1_ItemDataBound(Object sender, RepeaterItemEventArgs e)
at System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean useDataSource)
at System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e)
at _Default.up1_Load()
at _Default.Timer1_Tick(Object sender, EventArgs e)
at System.Web.UI.Timer.OnTick(EventArgs e)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
I'm just trying to figure out exactly where the problem is happening and what it is - is it happening in the Repeater1_ItemDataBound sub routine, or in the Timer1_Tick sub routine? Is the last thing that happened before the error occured at the top or bottom of the trace?
any help much appreciated
thanks
The wikipedia entry on stack traces should help a little, but essentially a stack trace is a list of methods / functions that a thread / the program is in at a given time (usually during an exception).
The top most line in a stack trace is the method / function that the thread / program is "currently in" (i.e. currently executing), the next line is the method / function that is calling the method given in the line above, etc...
So for example, if I have the following code (in C#):
void Timer1_Tick()
{
SomeMethod();
}
void SomeMethod()
{
AnotherMethod();
}
void AnotherMethod()
{
// Suppose I have a exception / stack trace taken at this point
}
I might get the following stack trace:
AnotherMethod()
SomeMethod()
Timer1_Tick()
In short - its likely that your error is somewhere in the method Repeater1_ItemDataBound, as that is the "outermost" / topmost method in your stack trace.
Read it from bottom to top - the function where the exception occurred is at the top.
In your itemdatabound but there is no evidence of what the error is, its a trace so 1st thing is the upper most (last) problem and the items below it are the route it took to get there
It looks like you are casting something wrong, maybe a control? e.g a textbox to a label by mistake?
I am stuck into a problem here and need a hint from someone.
I am using my own SQL Server database for managing users and roles (as opposed to aspnet DB). It was working fine until I added some custom fields to the aspnet_membership table. After doing so, I cannot create a new user through the asp.net web administration tool. The following exception is thrown:
An error was encountered. Please return to the previous page and try again.
The following message may help in diagnosing the problem: Exception has been thrown by the target of an invocation. at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Web.Administration.WebAdminMembershipProvider.CallWebAdminMembershipProviderHelperMethodOutParams(String methodName, Object[] parameters, Type[] paramTypes) at System.Web.Administration.WebAdminMembershipProvider.CreateUser(String username, String password, String email, String passwordQuestion, String passwordAnswer, Boolean isApproved, Object providerUserKey, MembershipCreateStatus& status) at System.Web.UI.WebControls.CreateUserWizard.AttemptCreateUser() at System.Web.UI.WebControls.CreateUserWizard.OnNextButtonClick(WizardNavigationEventArgs e) at System.Web.UI.WebControls.Wizard.OnBubbleEvent(Object source, EventArgs e) at System.Web.UI.WebControls.CreateUserWizard.OnBubbleEvent(Object source, EventArgs e) at System.Web.UI.WebControls.Wizard.WizardChildTable.OnBubbleEvent(Object source, EventArgs args) at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) at System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
This occurs only at the time of user creation. Everything else is working fine. I have already tried running the aspnet_regsql utility again. Any other suggestions? Any help will be most appreciated.
--
Ali
At a guess, are any of the fields you have added defined as Not NULL and have no defaults?
If so, make sure you populate them in the code that addes a user.
Are the extra columns allowed to hold null values? Have you defined suitable default values if they aren't?
Did you update the Stored Procedures that write to the membership tables? If so, then you'll need to write a custom membership provider to populate them - what sort of details are they?
It would probably be better to store these values against a Profile for the user - unless they are explicitly to do with their membership, in which a custom provider is the way to go.
Edit to respond to Ali's comments
In that instance (marking an account as deleted/inactive) then yes, it probably makes sense to store that against the membership table - they are to do with the users membership of the site.
However - the main issue I can see with your approach is that if you're using the default Login controls, the user can still log in initially, and then you'd need to be checking the value of the Deleted field in either the LoggingIn (before Authentication) or LoggedIn (after) event handlers - you might be able to get away with modifying the built in IsApproved property to handle this by default.
Thanks Zhaph and Oded. The NULL values were problem.
But Zhaph pointed out towards another issue I would like to know more. The additional details are like isDeleted, where I just mark isDeleted as true without actually having to delete the user and then some relevant details for audit like deletedByUser, dateDeleted etc. (and some application specific).
I did not update the stored procedures that write to the membership tables. Instead, I have some additional SPs which fill in the extra details as soon as the user is created. Is that(storing field in membership table and writing new procedures) a correct way to approach?