Friday, January 9, 2009

Update for .NET 3.5 SP1 Released

First you can search for KB959209 in the Microsoft knowledge base for details on this update. Here is the URL for the article: http://support.microsoft.com/kb/959209.
This update addresses following issues that may affect an ASP.NET developer that has .NET 3.5 SP1 installed:
- Dynamic Data used with Entity Framework generates an error when navigating one to one relationships
- BrowserCaps generates an error if Front Page Server extensions are installed.
- Using a derived UpdateProgress control may encounter an exception.
- An exception is thrown if the website is using WPF to generate images and the site is hosted under IIS.

Thursday, January 1, 2009

Globally trap unhandeld exceptions using VB.Net and Winforms

Don't worry if your windows application don't have any exception block. Using Application.vb or Application.ThreadException we can trap unhandeled exceptions in our application. There are two ways we can accomplish this Job.
1. Using Application.vb file : If your application does not starts with Main function, then we can use Application.Vb file and catch the unhandeled exceptions.
2. Write code in Sub Main : If you have Sub Main() function in the application. we can not create Application.Vb file. That time kindly follow the following steps to catch the unhandled exception.
Following are the steps those will help us to trap exceptions.
i) Create the handeler in the Sub main Method
Public Sub Main()
'To Call any Unhandled Exception thrown by Current Application Thread
AddHandler Application.ThreadException, AddressOf Application_ThreadException
'Write other code here
End Sub
Once we create declare the above handler, any handeled exception generated in the current thread will call the "Application_ThreadException" function.

ii). Create the Application_ThreadException function and catch the exception.
'Application_ThreadException will be called if Unhandled Exception thrown by Current Application Thread
Private Sub Application_ThreadException(ByVal sender As Object, ByVal e As Threading.ThreadExceptionEventArgs)
If (e.Exception.GetType().Name.ToUpper = "OUTOFMEMORYEXCEPTION") Then
GC.Collect()
End If
' Supress Certain types of errors only , else dispaly the error message
If (e.Exception.GetType().Name.ToUpper <> "OUTOFMEMORYEXCEPTION" _

And e.Exception.GetType().Name.ToUpper <> "OBJECTDISPOSEDEXCEPTION") Then
Dim result As DialogResult = DialogResult.Cancel

Try
result = ShowThreadExceptionDialog(e.Exception)
Catch
Try
MessageBox.Show("Fatal Error", _
"Fatal Error", _
MessageBoxButtons.AbortRetryIgnore, _
MessageBoxIcon.Stop)
Finally
Application.Exit()
End Try
End Try
If (result = DialogResult.Abort) Then

Application.Exit()
End If
End If
End Sub


Private Function ShowThreadExceptionDialog(ByVal e As Exception) As DialogResult
Dim stack As New StackTrace(e, True)
Dim result = stack.ToString()
Dim errorMsg As String = " Unhandled Exception :" & e.Message & vbCrLf & vbCrLf
errorMsg &= vbCrLf & vbCrLf & "Stack Trace:" & _

vbCrLf & result
Return MessageBox.Show(errorMsg, _
Application.ProductName, _
MessageBoxButtons.AbortRetryIgnore, _
MessageBoxIcon.Stop)
End Function

Happy Coding..