Is there any interesting data I could obtain from Application_End() parameters? - c#

In my ASP.NET application that I deploy on Windows Azure I want to log as many useful data as possible. There's Application_End() method:
protected void Application_End(object sender, EventArgs e)
{
}
which is invoked with sender being System.Web.HttpApplicationFactory and e being just System.EventArgs. With such parameters all I can do is just log their types which isn't very useful.
Can I obtain any useful data from these parameters? Are there cases when Application_End() is invoked with parameters that have other - more useful - actual types?

IIS, class HttpRuntime included, sources can be downloaded. Careful analysis shows that indeed the event parameters are always the same and convey no useful information. The call stack for the event is also useless - it is always
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()
but... There is System.Web.Hosting.HostingEnvironment.ShutdownReason that can be retrieved from within Application_End() and that is set by HttpRuntime when the application shutdown is being initiated.
So the "interesting data" is System.Web.Hosting.HostingEnvironment.ShutdownReason.
Also see this closely related question

Related

How to check valid object in PropertyDescriptor?

I'm working in WinForms application and used the BindingList datasource. I need to check the whether the object is valid or not with PropertyDescriptor. because
PropertyDescriptor.GetValue(object obj) will works for valid object. but sometimes i has the "TargetInvocationException". So i want to check if that object is valid or not before get the value.
[https://i.stack.imgur.com/VsdeW.png]
here is the stacktrace:
System.Reflection.TargetException: Object does not match target type.
at System.Reflection.RuntimeMethodInfo.CheckConsistency(Object target)
at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.SecurityUtils.MethodInfoInvoke(MethodInfo method, Object target, Object[] args)
at System.ComponentModel.ReflectPropertyDescriptor.GetValue(Object component)
--- End of inner exception stack trace ---
at System.ComponentModel.ReflectPropertyDescriptor.GetValue(Object component)
In the case that you will already need to execute the call, it will be far easier and less expensive to just try the call and do something different if it fails.
try
{
PropertyDescriptor.GetValue(...);
}
catch (TargetException ex)
{
// do the thing you would do if the object wasn't valid.
}

Error when running JSON.NET

I have added the using statement to the class I am running:
using Newtonsoft.Json.Linq;
And I am referencing the Newtonsoft.Json.dll in the same project.
I get no compile-time errors. But I do get a run-time one. I cant even do simple code like this (the hello doesn't show up before crashing):
public void Main()
{
MessageBox.Show("hello");
JObject j = new JObject();
Dts.TaskResult = (int)ScriptResults.Success;
}
I get the following error:
DTS Script Task has encountered an exception in user code: Exception has been thrown by the target of an invocation
With the following StackTrace:
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.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()
Anyone know what this might be causing this?

Bing Maps - WebException was unhandled

I am trying to implement bing maps in my project. I just drag and drop the map into Map page.
Now i just navigate from the main page to Map page. When map is loaded I get exception that is
WebException was unhandled
Error Message is:
System.Net.WebException was unhandled
Message=The remote server returned an error: NotFound.
StackTrace:
at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
at System.Net.Browser.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at SharpGIS.GZipHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at Microsoft.Phone.Controls.Maps.Map.LogResponse(IAsyncResult result)
at System.Net.Browser.ClientHttpWebRequest.<>c__DisplayClassa.<InvokeGetResponseCallback>b__8(Object state2)
at System.Threading.ThreadPool.WorkItem.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadPool.WorkItem.doWork(Object o)
at System.Threading.Timer.ring()
InnerException: System.Net.WebException
Message=The remote server returned an error: NotFound.
StackTrace:
at System.Net.Browser.ClientHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
at System.Net.Browser.ClientHttpWebRequest.<>c__DisplayClass2.<EndGetResponse>b__1(Object sendState)
at System.Net.Browser.AsyncHelper.<>c__DisplayClass4.<BeginOnUI>b__0(Object sendState)
at System.Reflection.RuntimeMethodInfo.InternalInvoke(RuntimeMethodInfo rtmi, Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark)
at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at System.Delegate.DynamicInvokeOne(Object[] args)
at System.MulticastDelegate.DynamicInvokeImpl(Object[] args)
at System.Delegate.DynamicInvoke(Object[] args)
at System.Windows.Threading.Dispatcher.<>c__DisplayClass4.<FastInvoke>b__3()
at System.Reflection.RuntimeMethodInfo.InternalInvoke(RuntimeMethodInfo rtmi, Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark)
at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at System.Delegate.DynamicInvokeOne(Object[] args)
at System.MulticastDelegate.DynamicInvokeImpl(Object[] args)
at System.Delegate.DynamicInvoke(Object[] args)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.Dispatch(DispatcherPriority priority)
at System.Windows.Threading.Dispatcher.OnInvoke(Object context)
at System.Windows.Hosting.CallbackCookie.Invoke(Object[] args)
at System.Windows.Hosting.DelegateWrapper.InternalInvoke(Object[] args)
at System.Windows.RuntimeHost.ManagedHost.InvokeDelegate(IntPtr pHandle, Int32 nParamCount, ScriptParam[] pParams, ScriptParam& pResult)
I did not do any other functions. Just Navigate to one page to another page. Please let me know why this error is happen?
Thanks in advance..
Key is the problem. Now only i realize that Bing Map Key is very important for real time project. Now i cleared my problem.
<Grid x:Name="MapPageUIContainer" Grid.Row="1" Margin="2,0,2,0">
<my:Map Height="688" HorizontalAlignment="Left" Margin="0,80,0,0" Name="map1" VerticalAlignment="Top" Width="478" CredentialsProvider="My Key"/>
</Grid>
Now it is working fine.
Thanks to all Who give support to me to find the problem. Thank you.

background transfer count windows phone

I'm to download files using Background Transfer Service for WP7 but the problem is sometimes my app crash for still unknown reasons for me and when i try to launch it again it just crash again with the following error.
System.UriFormatException was unhandled Message=Invalid URI: The
format of the URI could not be determined. StackTrace: at
System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
at System.Uri..ctor(String uriString) at
Microsoft.Phone.BackgroundTransfer.BtsApi.QueryBackgroundTransferRequestTransferParameters(BtsRequestHandle
requestHandle) at
Microsoft.Phone.BackgroundTransfer.BackgroundTransferRequest..ctor(BtsRequestHandle
requestHandle, String requestId, RequestStatus requestStatus) at
Microsoft.Phone.BackgroundTransfer.BackgroundTransferService.BackgroundTransferRequestsEnumerator.MoveNext()
at Transffr.MainPage.InitialTansferStatusCheck() at
Transffr.MainPage.OnNavigatedTo(NavigationEventArgs e) at
Microsoft.Phone.Controls.PhoneApplicationPage.InternalOnNavigatedTo(NavigationEventArgs
e) at
System.Windows.Navigation.NavigationService.RaiseNavigated(Object
content, Uri uri, NavigationMode mode, Boolean isNavigationInitiator,
PhoneApplicationPage existingContentPage, PhoneApplicationPage
newContentPage) at
System.Windows.Navigation.NavigationService.CompleteNavigation(DependencyObject
content, NavigationMode mode) at
System.Windows.Navigation.NavigationService.ContentLoader_BeginLoad_Callback(IAsyncResult
result) at
System.Windows.Navigation.PageResourceContentLoader.BeginLoad_OnUIThread(AsyncCallback
userCallback, PageResourceContentLoaderAsyncResult result) at
System.Windows.Navigation.PageResourceContentLoader.<>c_DisplayClass4.b_0(Object
args) at
System.Reflection.RuntimeMethodInfo.InternalInvoke(RuntimeMethodInfo
rtmi, Object obj, BindingFlags invokeAttr, Binder binder, Object
parameters, CultureInfo culture, Boolean isBinderDefault, Assembly
caller, Boolean verifyAccess, StackCrawlMark& stackMark) at
System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj,
BindingFlags invokeAttr, Binder binder, Object[] parameters,
CultureInfo culture, StackCrawlMark& stackMark) at
System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at System.Delegate.DynamicInvokeOne(Object[] args) at
System.MulticastDelegate.DynamicInvokeImpl(Object[] args) at
System.Delegate.DynamicInvoke(Object[] args) at
System.Windows.Threading.DispatcherOperation.Invoke() at
System.Windows.Threading.Dispatcher.Dispatch(DispatcherPriority
priority) at System.Windows.Threading.Dispatcher.OnInvoke(Object
context) at System.Windows.Hosting.CallbackCookie.Invoke(Object[]
args) at
System.Windows.Hosting.DelegateWrapper.InternalInvoke(Object[] args)
at System.Windows.RuntimeHost.ManagedHost.InvokeDelegate(IntPtr
pHandle, Int32 nParamCount, ScriptParam[] pParams, ScriptParam&
pResult)
which i don't understand because is in this line of code:
if (TransferListBox.Items.Count > 0)
{
//Some code here
}
And i'm trying to count list items why does it tells me invalid URI?
And always crash using a valid Absolute URL.
Thanks for any help.

.NET 4 Deserialization issue: Illegal call to the reserved method

On some, but not all, machines when we try to deserialize some XML using (written in C#) System.Xml.Serialization.XmlSerializer.Deserialize(TextReader textReader)
we get a kind of security related error described in the error message and stack trace below. The exception is thrown by the assembly that gets generated by .NET when serializing/deserializing.
In the stack trace below, AggregateElement derives from Element.
We haven't had any problems with .NET 3.5 and our code hasn't changed since we've upgraded to .NET 4
Does anyone have any ideas on what and why this is?
Error: Illegal call to the reserved method 'Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderSheet.Read53_AggregateElement()' from 'Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderSheet.Read72_Element()'.
Call Stack Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderSheet.Read53_AggregateElement(Boolean isNullable, Boolean checkType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderSheet.Read72_Element(Boolean isNullable, Boolean checkType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderSheet.Read74_Section(Boolean isNullable, Boolean checkType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderSheet.Read70_SubForm(Boolean isNullable, Boolean checkType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderSheet.Read72_Element(Boolean isNullable, Boolean checkType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderSheet.Read74_Section(Boolean isNullable, Boolean checkType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderSheet.Read70_SubForm(Boolean isNullable, Boolean checkType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderSheet.Read92_Sheet(Boolean isNullable, Boolean checkType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderSheet.Read93_Sheet()
at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature 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.Xml.Serialization.TempAssembly.InvokeReader(XmlMapping mapping, XmlReader xmlReader, XmlDeserializationEvents events, String encodingStyle)
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
at System.Xml.Serialization.XmlSerializer.Deserialize(TextReader textReader)

Categories