How do I programmatically find why Application_End() is invoked? - asp.net

Application_End() is invoked when my application pool is stopped which can happen for a number of reasons, including automatic pool recycle or changes in the folder from which the application is served.
The call stack will typically looks like this:
my Application_End(Object sender, EventArgs e)
at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType 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.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at System.Web.HttpApplication.InvokeMethodWithAssert(MethodInfo method, Int32 paramCount, Object eventSource, EventArgs eventArgs)
at System.Web.HttpApplication.ProcessSpecialRequest(HttpContext context, MethodInfo method, Int32 paramCount, Object eventSource, EventArgs eventArgs, HttpSessionState session)
at System.Web.HttpApplicationFactory.Dispose()
at System.Web.HttpRuntime.Dispose()
at System.Web.HttpRuntime.ReleaseResourcesAndUnloadAppDomain(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
which is completely useless.
How do I programatically find why it was called?

There's System.Web.Hosting.HostingEnvironment.ShutdownReason property that indicates why the application is being terminated. Its value can be retrieved from inside Application_End().

Related

Http exception gets wrapped as System.Reflection.TargetInvocationException

I want to know why is the exception type is being changed when I dont use method.invoke() or such from System.Reflection
Stack Trace
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an
invocation. ---> System.Web.HttpException: Forbidden
at Global.SetSession() in Global.asax.vb:line 193
at Global.Application_AcquireRequestState() Global.asax.vb:line 292
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig,
Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters,
Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder
binder, Object[] parameters, CultureInfo culture)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at System.Web.Util.ArglessEventHandlerProxy.Callback(Object sender, EventArgs e)
at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&
completedSynchronously)
what the Stack trace looks like on a similar App in the same scenario
System.Web.HttpException (0x80004005): wazzzup
at Global.SetSession() in Global.asax.vb:line 77
at Global.Application_AcquireRequestState(Object sender, EventArgs e) in Global.asax.vb:line
142
at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&
completedSynchronously)

How to catch a resource assembly not found exception under .net framework 4?

I recently switched a DotNetNuke 6 install to a .net 4 framework, and i've started getting the following error:
DotNetNuke.Services.Exceptions.PageLoadException: Exception has been thrown by the target of an invocation. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileNotFoundException: Could not find file 'Telerik.Web.UI.resources'.
at System.Reflection.RuntimeAssembly.InternalGetSatelliteAssembly(String name, CultureInfo culture, Version version, Boolean throwOnFileNotFound, StackCrawlMark& stackMark)
at System.Resources.ManifestBasedResourceGroveler.GetSatelliteAssembly(CultureInfo lookForCulture, StackCrawlMark& stackMark)
at System.Resources.ManifestBasedResourceGroveler.GrovelForResourceSet(CultureInfo culture, Dictionary`2 localResourceSets, Boolean tryParents, Boolean createIfNotExists, StackCrawlMark& stackMark)
at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo requestedCulture, Boolean createIfNotExists, Boolean tryParents, StackCrawlMark& stackMark)
at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents)
at System.Resources.ResourceManager.GetString(String name, CultureInfo culture)
at Telerik.Web.LocalizationProvider.EmbeddedResourceLocator.GetString(String resourceKey)
at Telerik.Web.LocalizationStrings.GetString(String key, Boolean throwErrorIfMissing)
at Telerik.Web.LocalizationStrings.GetString(String key)
at Telerik.Web.UI.ComboBoxStrings.get_AllItemsCheckedString() --- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Web.SecurityUtils.MethodInfoInvoke(MethodInfo method, Object target, Object[] args)
at System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)
at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember)
at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember)
at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, StringBuilder output, SerializationFormat serializationFormat)
at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, SerializationFormat serializationFormat)
at Telerik.Web.UI.RadComboBox.DescribeComponent(IScriptDescriptor descriptor)
at Telerik.Web.UI.RadDataBoundControl.Telerik.Web.IControl.DescribeComponent(IScriptDescriptor descriptor)
at Telerik.Web.UI.ScriptRegistrar.GetScriptDescriptors(Control control)
at Telerik.Web.UI.RadDataBoundControl.GetScriptDescriptors()
at Telerik.Web.UI.RadDataBoundControl.System.Web.UI.IScriptControl.GetScriptDescriptors()
at System.Web.UI.ScriptControlManager.RegisterScriptDescriptors(IScriptControl scriptControl)
at Telerik.Web.UI.RadDataBoundControl.RegisterScriptDescriptors()
at Telerik.Web.UI.RadDataBoundControl.Render(HtmlTextWriter writer)
at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
at System.Web.UI.Control.RenderControl <....snip, rendering call stack>
I have no idea why this error happens since i can't reproduce it on another server, or even on the same server. Since i don't find a solution i'm trying to patch it so i looked at the workaround proposed in this post:
http://social.msdn.microsoft.com/Forums/vstudio/en-US/32e458a1-7443-4309-a054-8839b33dfd4f/framework-40-dll-loaded-by-a-20-executable-cannot-find-xxxxresourcesdll
So the workaround would be to
catch the FileNotFoundException in HostRuntime.ResolveAssembly and return null. This should prevent the process from crashing.
I can add some code to the application through a HttpModule, but i really don't see how i'm supposed to patch the HostRuntime.ResolveAssembly... any idea?
Edit: I've been diggin in the mscorlib assembly for the framework 4 and i see something very weird:
The call from the ManifestBasedResourceGroveler to the SatelliteAssembly loading is the following:
try
{
runtimeAssembly = this._mediator.MainAssembly.InternalGetSatelliteAssembly(satelliteAssemblyName, lookForCulture, this._mediator.SatelliteContractVersion, false, ref stackMark);
}
catch (FileLoadException ex)
{
int hResult = ex._HResult;
Win32Native.MakeHRFromErrorCode(5);
}
catch (BadImageFormatException)
{
}
So it catches exceptions, but here is the code for InternalGetSatelliteAssembly
if (runtimeAssembly == this)
{
throw new FileNotFoundException(string.Format(culture, Environment.GetResourceString("IO.FileNotFound_FileName"), new object[]
{
assemblyName.Name
}));
}
Ok, so i will always get a FileNotFoundException that won't be caught... that looks like a really weird behavior to me
Based on the stack trace it looks like a Telerik version issue. Are you sure that the proper assemblies are all loaded?

Minus 2 value in FastReport.net

I want to Minus to value in FastReport.Net in footer.
my Code :
private void PageFooter1_BeforeLayout(object sender, EventArgs e)
{
Text22.Text=Convert.ToString(Convert.ToDouble(Text12.Text)-Convert.ToDouble(Text3.Text));
}
and this error was occurs:
FastReport.Net v1.7.33
Exception has been thrown by the target of an invocation.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.FormatException: Input string was not in a correct format.
at System.Number.ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt)
at FastReport.ReportScript.PageFooter1_BeforeLayout(Object sender, EventArgs e)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType 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 FastReport.Code.ExpressionDescriptor.Invoke(Object[] parameters)
at FastReport.BandBase.CalcHeight()
at FastReport.Engine.ReportEngine.ShowBandToPreparedPages(BandBase band, Boolean getData)
at FastReport.Engine.ReportEngine.ShowBand(BandBase band, Boolean getData)
at FastReport.Engine.ReportEngine.EndLastPage()
at FastReport.Engine.ReportEngine.RunReportPage(ReportPage page)
at FastReport.Engine.ReportEngine.RunReportPages()
at FastReport.Engine.ReportEngine.RunReportPages(ReportPage page)
at FastReport.Engine.ReportEngine.Run(Boolean runDialogs, Boolean append, ReportPage page)
at FastReport.Report.Prepare(Boolean append)
at FastReport.Design.ReportTab.Preview()
can anyone help me ?
You can try to do DataTextFormatString="{0:Axx}", and put the code into the BeforePrint event.
For example:
private void Text14_BeforePrint(object sender, EventArgs e)
{
Text14.Text=string.Format("{0:N}",((Decimal)Report.GetColumnValue("Table.money"))-((Decimal)Report.GetColumnValue("Table.TRSMONEY")));
}

Error Updating Dynamic Entity When Setting Property Value of Type PickList

I've added a custom attribute ("custom_contacttype") to the Contact entity. This attribute is of type picklist which is comprised of seven values. I'm developing using Advanced Developer Extensions for Microsoft Dynamics CRM against CRM 4.0. After I set the value for this attribute and call SaveChanges() I get "Object reference not set to an instance of an object." error. I've been battling this one for a while. What am I doing wrong? Below is my code:
var crm = new CrmDataContext(context.Connection);
var saveContact = crm.GetEntities("contact").Where(p => p.GetPropertyValue<Guid> ("contactid") == contact.Id.Value).Single();
saveContact.SetPropertyValue("custom_contacttype", 2, typeof(Picklist));
crm.UpdateObject(saveContact);
crm.SaveChanges();
Trace Log from CRM Server:
[2011-07-01 16:39:33.7] Process: w3wp |Organization:f827deb3-c6cc-df11-bc07-005056887b79 |Thread: 8 |Category: Platform.Sdk |User: 822138f1-c574-e011-9dca-005056887b79 |Level: Error | PluginStep.Execute
at PluginStep.Execute(PipelineExecutionContext context)
at Pipeline.Execute(PipelineExecutionContext context)
at MessageProcessor.Execute(PipelineExecutionContext context)
at InternalMessageDispatcher.Execute(PipelineExecutionContext context)
at ExternalMessageDispatcher.Execute(String messageName, Int32 primaryObjectTypeCode, Int32 secondaryObjectTypeCode, PropertyBag fields, CorrelationToken correlationToken, CallerOriginToken originToken, UserAuth userAuth, Guid callerId)
at CrmServiceInternal.Update(String namespaceName, BusinessEntityBase entity, CorrelationToken correlationToken, CallerOriginToken originToken, UserAuth userAuth, Guid callerId)
at CrmService.Update(BusinessEntity entity)
at RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at LogicalMethodInfo.Invoke(Object target, Object[] values)
at WebServiceHandler.Invoke()
at WebServiceHandler.CoreProcessRequest()
at SyncSessionlessHandler.ProcessRequest(HttpContext context)
at CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
at ApplicationStepManager.ResumeSteps(Exception error)
at HttpApplication.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
at HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr)
at HttpRuntime.ProcessRequestNoDemand(HttpWorkerRequest wr)
at ISAPIRuntime.ProcessRequest(IntPtr ecb, Int32 iWRType)
Web Service Plug-in failed in SdkMessageProcessingStepId: {27DF4121-19BC-DF11-A90E-005056887B79}; EntityName: contact; Stage: 10; MessageName: Update; AssemblyName: AccessCRM.ChangeLogContactData, AccessCRM, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a030c130976783ab; ClassName: AccessCRM.ChangeLogContactData; Exception: Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
at AccessCRM.PluginUtilities.GetStringValueFromProperty(Property p)
at AccessCRM.ChangeLogContactData.Execute(IPluginExecutionContext context)
at Microsoft.Crm.Extensibility.PluginStep.Execute(PipelineExecutionContext context)
.
[2011-07-01 16:39:33.7] Process: w3wp |Organization:f827deb3-c6cc-df11-bc07-005056887b79 |Thread: 8 |Category: Platform.Sdk |User: 822138f1-c574-e011-9dca-005056887b79 |Level: Error | PluginExecutionExceptionHandler.Handle
at PluginExecutionExceptionHandler.Handle(Stream from, Stream to, Exception exception)
at CompositeSoapExtensionExceptionHandler.Handle(Stream to, Stream from, Exception exception)
at CrmAuthenticationSoapExtensionBase.ProcessMessage(SoapMessage message)
at SoapMessage.RunExtensions(SoapExtension[] extensions, Boolean throwOnException)
at SoapServerProtocol.WriteException(Exception e, Stream outputStream)
at WebServiceHandler.WriteException(Exception e)
at WebServiceHandler.Invoke()
at WebServiceHandler.CoreProcessRequest()
at SyncSessionlessHandler.ProcessRequest(HttpContext context)
at CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
at ApplicationStepManager.ResumeSteps(Exception error)
at HttpApplication.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
at HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr)
at HttpRuntime.ProcessRequestNoDemand(HttpWorkerRequest wr)
at ISAPIRuntime.ProcessRequest(IntPtr ecb, Int32 iWRType)
CrmSoapExtension detected InvalidPluginExecutionException:
System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> Microsoft.Crm.Sdk.InvalidPluginExecutionException: Object reference not set to an instance of an object. ---> System.NullReferenceException: Object reference not set to an instance of an object.
at AccessCRM.PluginUtilities.GetStringValueFromProperty(Property p)
at AccessCRM.ChangeLogContactData.Execute(IPluginExecutionContext context)
at Microsoft.Crm.Extensibility.PluginStep.Execute(PipelineExecutionContext context)
--- End of inner exception stack trace ---
at Microsoft.Crm.Extensibility.PluginStep.Execute(PipelineExecutionContext context)
at Microsoft.Crm.Extensibility.Pipeline.Execute(PipelineExecutionContext context)
at Microsoft.Crm.Extensibility.MessageProcessor.Execute(PipelineExecutionContext context)
at Microsoft.Crm.Extensibility.InternalMessageDispatcher.Execute(PipelineExecutionContext context)
at Microsoft.Crm.Extensibility.ExternalMessageDispatcher.Execute(String messageName, Int32 primaryObjectTypeCode, Int32 secondaryObjectTypeCode, PropertyBag fields, CorrelationToken correlationToken, CallerOriginToken originToken, UserAuth userAuth, Guid callerId)
at Microsoft.Crm.Sdk.CrmServiceInternal.Update(String namespaceName, BusinessEntityBase entity, CorrelationToken correlationToken, CallerOriginToken originToken, UserAuth userAuth, Guid callerId)
at Microsoft.Crm.Sdk.Crm2007.CrmService.Update(BusinessEntity entity)
--- End of inner exception stack trace ---
Looking at the stack trace, the error is actually being thrown in a plugin, not in the code you have pasted above. Look at this line in particular:
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
at AccessCRM.PluginUtilities.GetStringValueFromProperty(Property p)
at AccessCRM.ChangeLogContactData.Execute(IPluginExecutionContext context)
You'd need to post up the code for that plugin for us to have another look.
Alternatively use Remote Debugging to debug this yourself.

Error Asp.net Membership Provider when adding user

The error message below i get when I"m trying to create a new user in a project management system we use for a client. I type in all the corresponding information then when I click create it throws this error.
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)
What causes this error is the hard drive where all databases are being stored is full. Even if there is 1kb left it will post the error. To fix, install a much larger hard drive, or clear any unnecessary files from the hard drive and make free space. the server error or asp.net error you may see from this is the 9002 error. When the hard drive is full the databases log file cannot be written too, which when anything is done to the database, inserting, updating, etc. it is written to the log file. When there is no space left the log file cannot expand therefore throwing an error. I appreciate your help chriskent. By the way if anyone is wondering we had no room left literally not even 1kb to spare, our free space was 0kb. Hope this helps.
Do you have a machine key element in your web.config? Ensure this is specifically set (Not autogenerate). Check this thread for more information:
http://forums.asp.net/t/1213872.aspx

Resources