Getting Out of Memory Exception when you have plenty of Memory/RAM available

 

This is a great article on why having or adding more memory won’t fix your Out of Memory Exception.   Bottom line.. on a 32bit server you’re site will crash when it hits between 600MB and 800MB.  The amount varies based on what else is going on with the machine.   The solution? Basically, you have to upgrade to a 64bit OS or re-write your application.

 

Why adding more memory won’t fix your Out of Memory error by Edge

Copied from the article directly, in case it ever goes down.

-------------------------------------------

Here an interesting case. Consider there 2 scenarios:

Both are running the same website, both have the same amount of users connected.

Now imagine this website has a page to upload pictures, just like any regular photo-album website.

For some reason, at some point the users complain that they see an error page indicating out of memory error.

So, you wonder: How come? they are just uploading a photo to my website, and I still have plenty of memory in my server anyway.

Anyhow, you stop thinking about this and go for the easiest, quick and dirty solution: If the system tells me that my computer does not have enough memory then I just need to add more memory. Right?

And guess what? you still will get the error message.

That's a very common mistake. Having a machine with 10GB of memory does not mean you will have 10GB of memory available. I explain.

It does not matter if your computer or server has 512 MB, 1 GB, 2 GB, 4 GB or 8 GB of RAM. If your machine is a 32-bit machine it will only be able to see/manage 4 GB. That's mathematics, that's life, that's the way things are and you can't do nothing about it. A 32-bit machine can not do more than that.

Additional memory may increase your system performance, but it won't increase the memory availability. Sure your computer will use less the hard disk for swapping operations and will be able put more stuff in memory and start some programs faster, but 4GB is the limit; after this point the memory management module will start doing disk swap and to use the famous page file.

And here comes more bad news: Your Windows system on a 32-bit machine requires 2 GB allocated only for it.

So, if you have 4 GB installed, effectively you will have 2 GB only for applications; your windows will be using alone 2 GB.

So, what does out of memory means?

Well, according to some people at Microsoft, this limit for an average configuration is reached between 600 MB and 800 MB of utilization. That 800 number is NOT A RULE, is a baseline. Generally speaking the largest majority of configurations with website, .NET and SQL Server database might have a problem around this point. Of course, this can vary from system to system...as a matter of fact a system can be out of memory at just 600 MB.

Yes, it does sounds crazy. You look so happy now that you just bought a 4GB RAM notebook and your computer is breaking with just 800MB, hun?

Here is another point for you. Have you ever seen someone bragging that he/she bought a 10-megapixel camera and now he/she believes their pictures are going to be better because of this?

Well, guess what? Just like the number of megapixels in a camera box does not have much to do with picture quality, RAM memory does not have much to do with hard disk space.

That's a common mistake: People buy RAM as if they were buying a hard disk.

RAM usage needs to me continuous, unlike hard disk. A simple 5MB Microsoft Word document when saved in a hard disk can be split up in hundreds of pieces; When you open this file in memory, the RAM requires those 5MB to be allocated continuously.

Can you see now the reason for the 'out of memory' message?

Yes, it really means 'there is not enough continuous memory to place that file in memory'. Your system might have 2GB of RAM but unfortunately it might be too busy with stuff running and there is no enough continuous memory to put the picture you are uploading.

Yeah, you can not do much but you can buy a 64-bit machine then when you add more memory you can really use it more efficiently. And yes, we have Microsoft Windows systems for 64-bit machines.

If you do not want to buy a new system of upgrade you current server to a better version then you should think other solutions in the business process, such as to avoid users upload pictures with more than 1 MB in size to be uploaded.

Leave VB.NET for C#?

I’ve been posting all my code in VB.NET and if you haven't figured out by now; it’s my choice of language.  

Recently I’ve been debating on moving to C# but am reluctant.  Then I ran across this article my friend sent me.

Should I abandon VB.Net?

http://blogs.lessthandot.com/index.php/ITProfessionals/ProfessionalDevelopment/should-i-abandon-vb-net by chrissie1

He states it all perfectly. How VB.NET Developers feel. 

Should I abandon VB.Net? This is a question that crosses my mind from time to time, but lately it is getting stronger. At least it would make my life simpler. Copy paste coding gets even better when you are a C# programmer since there are so much more examples out there. The community is bigger and better for C#. Even Microsoft discourages the use of VB.Net. If you ever go to something like techdays you will find that VB.Net is nowhere to be found. In that community you will be mocked and ridiculed if you tell them you are a VB.Net programmer. You are looked down upon, even by the spaghetti programmers. But then the .Net community seems to be rude and unfriendly whatever you do. I noticed that when I did my little powershell series over the weekend.

So the question crosses my mind if I was wrong to choose VB.Net ….

Granted he’s a WinForms developer rather then a Web .NET Web Forms or MVC developer but it still applies.

Do I think I should change because of all of the reasons above? Nope, not any time soon.

and he ends it with a great statement:

Don't change things for the sake of change, change things for the better. Let's not forget that even the best and brightest get it wrong.

Read the full article: http://blogs.lessthandot.com/index.php/ITProfessionals/ProfessionalDevelopment/should-i-abandon-vb-net

Cyclomatic and Maintenance Complexity using CodeRush per Mark Miller

 

I’ve been using DevExpress’s Visual Studio Tool, CodeRush, for awhile now and I love it.

There’s been a feature though I was never familiar with, and that’s the little digits next to my methods. Choices of Cyclomatic Complexity, Maintenance Complexity and Line Count. Granted I figured out what Line Count was. 

image

So I did some research and found that Mike Miller from DevExpress has a Blog over there and goes over some CodeRush features that I found helpful.  I don’t know where his post on the Complexity count went but he did mention to another user on a forum post that there was this PDF which he describes the Complexity numbers.

Attachment Reference:

 

This has been helpful in alerting to me when I need to refractor my code and make changes, and break it out.

Here’s the charts from the PDF, which is the meat of it.

Cyclomatic Complexity

Probably the simplest measure of complexity. CC is the number of decision points for a method plus one. It also happens to represent the minimum number of test cases needed to travel through all branches of a method.

image

 

Maintenance Complexity

The purpose of Maintenance Complexity is to give you a picture of how much code you have in a given member.

 

image

 

Maintenance Complexity Points

Breakdown of how the Maintenance is counted

image

image

image

On Authentication Timeout - Save Web Form Contents

I was working on a project recently where I had to figure out how to persist user data in a web form after their Forms Authentication session as expired.

So I was thinking of ways to do this as I searched the know all Google. Walla!  Someone's already had to do this, why invent the wheel.  Found a post by Peter Ravnholt, on the MSDN site. http://code.msdn.microsoft.com/formsaver 

He Implements the HttpModule and handles saving the form state on FormAuthentication events. Really neat idea.  I tried is code, now keep in mind I'm doing this for Visual Basic, so I manually converted it all, but I couldn't get it work. Maybe I was converting something wrong.  I was getting "The state information is invalid for this page and might be corrupted."

Well RichardDeeming in the discussions for this post had an updated version that worked a little better then the original. http://code.msdn.microsoft.com/formsaver/Thread/View.aspx?ThreadId=88  Thanks to his code, I converted it to VB.Net and walla!  My pages now handle web content.

I'll post the converted VB version below. 

Thanks Richard and Peter if you ever find your names on here via Google :p

This is my VB version o the FormSaverHttpModule with Richard's changes.  I've modified it a bit since but this works.

Imports Microsoft.VisualBasic
Imports System.Security.Principal
Imports System.IO
Imports System.Web.Configuration
Imports System.Security.Permissions
 
''' <summary>
''' FormSaverModule Version 1.0
''' -Mastro:  Not my orignal idea, found this in use out on MSDN site. I manually converted it to VB
''' as the orignaly is in C#. No comments, so I'll add my own.
''' 
''' This class will handle every new request coming in and PostMapRequest. 
''' If user has Forms Authentication has timed out, class will save the state of the form into cache
''' with a Unique ID of that state to the user's cookie. 
''' 
''' When user logs back in, this class will check if they have the cookie set, if so it will then 
''' load that state back to their page and load the webcontent by generating a runtime transit page that
''' post submits the data back to the destination page and pre-fills in the values.
''' </summary>
''' <remarks></remarks>
<AspNetHostingPermission(SecurityAction.LinkDemand, Level:=System.Web.AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermission(SecurityAction.InheritanceDemand, Level:=AspNetHostingPermissionLevel.Minimal)> _
Public Class FormSaverHTTPModule
    Implements IHttpModule
 
#Region "Private Variables"
 
    Private Const CookieName As String = "#FormStateSaverModule/FormRestoreId"
    Private Shared ReadOnly StateCacheDuration As TimeSpan = TimeSpan.FromMinutes(40)
    Private Shared ReadOnly _AnonymousUser As IPrincipal = New GenericPrincipal(New GenericIdentity(String.Empty), Nothing)
    Private _FormsCookieName As String
    Private _LoginUrl As String
 
#End Region
 
    ''' <summary>
    ''' This class is required from the IHttpModule contract
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub Dispose() Implements System.Web.IHttpModule.Dispose
 
    End Sub
 
    ''' <summary>
    ''' This is the first method to run on application start
    ''' </summary>
    ''' <param name="Context"></param>
    ''' <remarks></remarks>
    Public Sub IHttpModuleInit(ByVal Context As HttpApplication) Implements System.Web.IHttpModule.Init
        Me.Init(Context) 'Lets call our Init and send the Application state along with it
    End Sub
 
    ''' <summary>
    ''' We call this Init Method from the IHttpModuleInit and send it the Application State
    ''' and then turn on Events to capture
    ''' </summary>
    ''' <param name="Context">Hold's the Application State</param>
    ''' <remarks></remarks>
    Protected Overridable Sub Init(ByVal Context As HttpApplication)
        If Context Is Nothing Then
            Throw New ArgumentNullException("context")
        End If
 
        _LoginUrl = FormsAuthentication.LoginUrl 'Store the Login page name
        _FormsCookieName = FormsAuthentication.FormsCookieName 'Store the Forms Authentication Cookie Name
 
        If Not String.IsNullOrEmpty(_LoginUrl) Then 'If LoginUrl Exists....
            Dim index As Integer = _LoginUrl.IndexOf("?"c) 'Search for a ? for query string
            If -1 <> index Then 'If ? was found....
                _LoginUrl = _LoginUrl.Substring(0, index) 'Grab the first part of the URL before the ? and set LoginUrl
            End If
        End If
 
        'Add Handlers that now raise events on every Application BeginRequest... and Application PostMapRequest
        AddHandler Context.BeginRequest, New EventHandler(AddressOf Application_BeginRequest)
        AddHandler Context.PostMapRequestHandler, New EventHandler(AddressOf Application_PostMapRequestHandler)
 
    End Sub
 
    ''' <summary>
    ''' A Delegate receiver method for the Application.BeginRequest Event
    ''' </summary>
    ''' <param name="sender">Object</param>
    ''' <param name="e">EventArgs</param>
    ''' <remarks></remarks>
    Protected Overridable Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
        Dim application As HttpApplication = DirectCast(sender, HttpApplication)
        Dim context As HttpContext = application.Context
 
        Dim cookie As HttpCookie = context.Request.Cookies(CookieName)
        If cookie IsNot Nothing AndAlso Not String.IsNullOrEmpty(cookie.Value) Then 'If Cookie exist and has value....
            Dim state As FormState = FormState.Load(cookie.Value) 'Lets try and load the state via the CookieID
 
            'Lets see if the State is valid now that it's loaded and it's originaly location matches where the user is trying to go
            If state IsNot Nothing AndAlso String.Equals(state.Path, context.Request.Path, StringComparison.OrdinalIgnoreCase) Then
                FormState.SetCurrent(context, state) 'State is valid and it's for this request so lets create the object of the state to be used later by Application_PostMapRequestHandler
                Return
            End If
        End If
 
        If IsPost(context) AndAlso Not IsAccessingLoginPage(context, _LoginUrl) Then 'If user is doing a Post back and it's not to the login page...
            cookie = context.Request.Cookies(_FormsCookieName) 'Load Authenication cookie
            If cookie IsNot Nothing Then
                Try
                    Dim ticket As FormsAuthenticationTicket = FormsAuthentication.Decrypt(cookie.Value)
                    If ticket IsNot Nothing AndAlso ticket.Expired AndAlso Not HasAnonymousAccess(context) Then 'If the user has expired.....
                        Dim state As FormState = FormState.Create(context) 'Store current state into cache
                        If state IsNot Nothing Then
                            cookie = New HttpCookie(CookieName, state.StateId) 'save cache ID into user's cookie
 
                            cookie.HttpOnly = True
                            context.Response.Cookies.Add(cookie)
                        End If
                    End If
                Catch generatedExceptionName As ArgumentException
                End Try
            End If
        End If
    End Sub
 
    Protected Overridable Sub Application_PostMapRequestHandler(ByVal sender As Object, ByVal e As EventArgs)
        Dim application As HttpApplication = DirectCast(sender, HttpApplication)
        Dim context As HttpContext = application.Context
 
        Dim state As FormState = FormState.GetCurrent(context) 'Get the context from the cache if it's there
        If state IsNot Nothing AndAlso state.Form IsNot Nothing AndAlso 0 <> state.Form.Count Then 'if the context was there....
            context.Handler = New FormStateSaverHandler(state) 'Then load the runtime transit page and post it back to destination page
        End If
    End Sub
 
    ''' <summary>
    ''' Returns Boolean if request is a Post request to page.
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Protected Shared Function IsPost(ByVal context As HttpContext) As Boolean
        Return String.Equals("POST", context.Request.HttpMethod, StringComparison.OrdinalIgnoreCase)
    End Function
 
    ''' <summary>
    ''' Return Boolean after it checks to see if content matches the LoginURL. Basically is the user 
    ''' going to the login page.
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Protected Shared Function IsAccessingLoginPage(ByVal context As HttpContext, ByVal loginUrl As String) As Boolean
        Dim result As Boolean = False
        If Not String.IsNullOrEmpty(loginUrl) Then
            If String.Equals(context.Request.Path, loginUrl, StringComparison.OrdinalIgnoreCase) Then
                result = True
            ElseIf -1 <> loginUrl.IndexOf("%"c) Then
                Dim temp As String = HttpUtility.UrlDecode(loginUrl)
                If String.Equals(context.Request.Path, temp, StringComparison.OrdinalIgnoreCase) Then
                    result = True
                Else
                    temp = HttpUtility.UrlDecode(loginUrl, context.Request.ContentEncoding)
                    If String.Equals(context.Request.Path, temp, StringComparison.OrdinalIgnoreCase) Then
                        result = True
                    End If
                End If
            End If
        End If
 
        Return result
    End Function
 
    ''' <summary>
    ''' Returns Boolean if the destination URL in question has anonymouse access.
    ''' </summary>
    ''' <param name="context"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Protected Shared Function HasAnonymousAccess(ByVal context As HttpContext) As Boolean
        Return UrlAuthorizationModule.CheckUrlAccessForPrincipal(context.Request.Path, _AnonymousUser, context.Request.HttpMethod)
    End Function
 
    ''' <summary>
    ''' This class becomes the actual FormState the user was on and is Serialzied and then saved 
    ''' </summary>
    ''' <remarks></remarks>
    <Serializable()> _
    Protected NotInheritable Class FormState
        Private Shared ReadOnly FormRestoreKey As New Object()
 
        Private ReadOnly _id As String
        Private ReadOnly _path As String
        Private ReadOnly _form As NameValueCollection
 
        Private Sub New(ByVal id As String, ByVal path As String, ByVal form As NameValueCollection)
            _id = id
            _path = path
            _form = form
        End Sub
 
        Public ReadOnly Property StateId() As String
            Get
                Return _id
            End Get
        End Property
 
        Public ReadOnly Property Path() As String
            Get
                Return _path
            End Get
        End Property
 
        Public ReadOnly Property Form() As NameValueCollection
            Get
                Return _form
            End Get
        End Property
 
        ''' <summary>
        ''' Loads the state that was set by Setcurrent and tries to return it as a FormState object.
        ''' Returns nothing if it's invalid.
        ''' </summary>
        ''' <param name="context"></param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Shared Function GetCurrent(ByVal context As HttpContext) As FormState
            If context Is Nothing Then
                Return Nothing
            End If
            Return TryCast(context.Items(FormRestoreKey), FormState)
        End Function
 
        ''' <summary>
        ''' Takes the state sent and creates a valid formstate object
        ''' </summary>
        ''' <param name="context"></param>
        ''' <param name="state"></param>
        ''' <remarks></remarks>
        Public Shared Sub SetCurrent(ByVal context As HttpContext, ByVal state As FormState)
            If context IsNot Nothing Then
                context.Items(FormRestoreKey) = state
            End If
        End Sub
 
        ''' <summary>
        ''' Takes the Context of the current Request Form and stores it into Cache with a Unique ID
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Shared Function Create(ByVal context As HttpContext) As FormState
            Dim result As FormState = Nothing
            If context IsNot Nothing AndAlso context.Request.Form IsNot Nothing AndAlso 0 <> context.Request.Form.Count Then
                Dim id As String = Guid.NewGuid().ToString()
                result = New FormState(id, context.Request.Path, context.Request.Form)
                HttpRuntime.Cache.Add("FormStateSaver_" + id, result, Nothing, Cache.NoAbsoluteExpiration, StateCacheDuration, CacheItemPriority.Normal, _
                Nothing)
            End If
            Return result
        End Function
 
        ''' <summary>
        ''' Loads the Context stored in Cache using the Unique ID
        ''' </summary>
        ''' <param name="id">Unique GUID</param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Shared Function Load(ByVal id As String) As FormState
            Dim result As FormState = Nothing
            If Not String.IsNullOrEmpty(id) Then
                result = TryCast(HttpRuntime.Cache("FormStateSaver_" + id), FormState)
            End If
 
            Return result
        End Function
 
        ''' <summary>
        ''' Deletes the stored Context from Cache
        ''' </summary>
        ''' <remarks></remarks>
        Public Sub Delete()
            HttpRuntime.Cache.Remove("FormStateSaver_" + _id)
        End Sub
    End Class
 
    ''' <summary>
    ''' This class is responsible for generating the Transit page on the fly. 
    ''' Basically a page that loads all the values then submits them back to the destination
    ''' page with the previous viewstate settings so that the form reloads the controls to where
    ''' they were prior.
    ''' 
    ''' This page quickly shows when the user is logging back in and loading a previous web form.
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Protected Class FormStateSaverHandler
        Implements IHttpHandler
 
        Private ReadOnly _state As FormState
 
        Public Sub New(ByVal state As FormState)
            _state = state
        End Sub
 
        Protected ReadOnly Property FormState() As FormState
            Get
                Return _state
            End Get
        End Property
 
        Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
            Get
                Return False
            End Get
        End Property
 
        Public Overridable Sub ProcessRequest(ByVal context As HttpContext) Implements System.Web.IHttpHandler.ProcessRequest
            Try
                Using writer As HtmlTextWriter = CreateHtmlTextWriter(context.Response.Output, context.Request.Browser)
                    Me.Render(writer)
                End Using
            Finally
                _state.Delete()
            End Try
        End Sub
 
        Protected Overridable Sub Render(ByVal writer As HtmlTextWriter)
            writer.RenderBeginTag(HtmlTextWriterTag.Html)
            writer.RenderBeginTag(HtmlTextWriterTag.Head)
            writer.RenderBeginTag(HtmlTextWriterTag.Title)
            writer.Write("Restoring form")
            writer.RenderEndTag()
            ' TITLE 
            writer.RenderEndTag()
            ' HEAD 
            writer.AddAttribute("onload", "document.forms[0].submit();")
            writer.RenderBeginTag(HtmlTextWriterTag.Body)
 
            writer.AddAttribute("method", "post")
            writer.RenderBeginTag(HtmlTextWriterTag.Form)
 
            Dim form As NameValueCollection = Me.FormState.Form
            For Each name As String In form.Keys
                RenderHiddenField(writer, name, form(name))
            Next
 
            'writer.AddAttribute(HtmlTextWriterAttribute.Align, "center")
            'writer.RenderBeginTag(HtmlTextWriterTag.P)
            'writer.Write("You should be redirected in a moment.")
            'writer.WriteFullBeginTag("br")
            'writer.Write("If nothing happens, please click ")
            'RenderSubmitButton(writer, "Submit")
            'writer.RenderEndTag()
            ' P 
            writer.RenderEndTag()
            ' FORM 
            writer.RenderEndTag()
            ' BODY 
            writer.RenderEndTag()
            ' HTML 
        End Sub
 
        Protected Shared Sub RenderHiddenField(ByVal writer As HtmlTextWriter, ByVal name As String, ByVal value As String)
            writer.AddAttribute(HtmlTextWriterAttribute.Type, "hidden")
            writer.AddAttribute(HtmlTextWriterAttribute.Name, name)
            writer.AddAttribute(HtmlTextWriterAttribute.Value, value)
            writer.RenderBeginTag(HtmlTextWriterTag.Input)
            writer.RenderEndTag()
            ' INPUT 
        End Sub
 
        Protected Shared Sub RenderSubmitButton(ByVal writer As HtmlTextWriter, ByVal text As String)
            writer.AddAttribute(HtmlTextWriterAttribute.Type, "submit")
            writer.AddAttribute(HtmlTextWriterAttribute.Value, text)
            writer.RenderBeginTag(HtmlTextWriterTag.Input)
            writer.RenderEndTag()
            ' INPUT 
        End Sub
 
        Protected Shared Function CreateHtmlTextWriter(ByVal writer As TextWriter, ByVal browser As HttpCapabilitiesBase) As HtmlTextWriter
            If browser Is Nothing Then
                Return New HtmlTextWriter(writer)
            End If
            Return browser.CreateHtmlTextWriter(writer)
        End Function
 
 
    End Class
 
 
End Class
 
 
 
 
 

 

Update: 6/10/10

Here is the original post, and it was moved to codeplex here.  Thanks Peter Revnholt!

IIS7 Windows7/Server2008 ApplicationPoolIdentity Security Change from Network Service

 

Yeah this one got me.. http://learn.iis.net/page.aspx/624/application-pool-identities/

The change microsoft made to have AppPool now run as “ApplicationPoolIdentity” instead of Network service.

So if you normally give Network Service rights needed to your webapp, you now have to stop doing that and change it to

IIS AppPool\DefaultAppPool

Or

IIS AppPool\<NAME OF YOUR APPPOOL>

End of that.

 

 

 

 

  1. Open Windows Explorer
  2. Select a file or directory.
  3. Right click the file and select "Properties"
  4. Select the "Security" tab
  5. Click the "Edit" and then "Add" button
  6. Click the "Locations" button and make sure you select your machine.
  7. Enter "IIS AppPool\DefaultAppPool" in the "Enter the object names to select:" text box.
  8. Click the "Check Names" button and click "OK".

By doing this the file or directory you selected will now also allow the "DefaultAppPool" identity access.

Microsoft Certification Step-By-Step Road Map for .NET Development, SQL 2008 Server, Team Foundation and Sharepoint

I’ve put together, from the Microsoft Site a Step-By-Step plan for getting certifications by Microsoft in the areas of .Net 3.5 Development, Team Foundation Server, Sharepoint and SQL 2008.

I’ve listed in order that you need to study and take exams that makes the most sense. The links go back to the Microsoft site Training/Certification pages.  This list is to make it easy.  Just follow it down and you study the book or e-learning class, then you take the listed exam and you get the listed certification.

Step Order

Study Press Book or E-Learning

Take This Exam

Get This Certification

 

.NET 3.5 Development Track (See Notes for 2.0 Track)

   

1

Microsoft Press Book

· MCTS Self-Paced Training Kit (Exam 70-536):
Microsoft .NET Framework--Application Development Foundation,
Second Edition

Microsoft E-Learning

· 5161AE: Advanced development with the Microsoft .NET
Framework 2.0 Foundation (16 Hours)

· 5160AE: Core development with the Microsoft .NET
Framework 2.0 Foundation (14 Hours)

Exam 70-536

 

2

Microsoft Press Book

· MCTS Self-Paced Training Kit (Exam 70-562):
Microsoft .NET Framework 3.5 - ASP.NET

Microsoft E-Learning

· 6463AE: Visual Studio 2008: ASP.NET 3.5 (20 Hours)

Exam 70-562

MCTS: .NET Framework 3.5, ASP.NET Applications

3

Classroom Training

· 01: Learning Plan for Designing and Developing ASP.NET Applications
Using the Microsoft .NET Framework 3.5 (Exam 70-564) (1 Forms)

Exam 70-564

MCPD: ASP.NET Developer 3.5 on Visual Studio 2008

Note: 2.0 Track

Since the previous exam has no book at this time, you can also take the .NET 2.0 Track Instead take Exam, Exam 70-528 and Exam 70-547 instead for 2.0 Certification.

 

MCTS: .NET Framework 2.0, ASP.NET Applications
AND
MCPD: Web Developer on Visual Studio 2005

4

Microsoft Press Book

· MCTS Self-Paced Training Kit (Exam 70-505):
Microsoft .NET Framework 3.5 -- Windows Forms Application Development

· MCTS Self-Paced Training Kit (Exam 70-526):
Microsoft .NET Framework 2.0 Windows-Based Client Development

Microsoft E-Learning

· 2546AE: Core Windows Client Development with
Microsoft Visual Studio 2005 (18 Hours)

· 2542AE: Advanced Data Access with
Microsoft Visual Studio 2005 (12 Hours)

· 2547AE: Advanced Windows Client Programming with
Microsoft Visual Studio 2005 (12 Hours)

· 2541AE: Core Data Access with
Microsoft Visual Studio 2005 (16 Hours)

Exam 70-505

 

5

Classroom Training

· 001: Learning Plan for Designing and Developing Windows
Applications Using the Microsoft .NET Framework 3.5 (Exam 70-563) (1 Forms)

Exam 70-563

MCPD: Windows Developer 3.5 on Visual Studio 2008

Note: 2.0 Track

Since the previous exam has no book at this time, you can also take the .NET 2.0 Track Instead take Exam, Exam 70-526 and Exam 70-548 instead for 2.0 Certification.

 

MCPD: Windows Developer on Visual Studio 2005

6

Microsoft Press Book

· MCTS Self-Paced Training Kit (Exam 70-561):
Microsoft .NET Framework 3.5 - ADO.NET

Microsoft E-Learning

· 6464AE: Visual Studio 2008: ADO.NET 3.5 (20 Hours)

Exam 70-561

 

7

Microsoft Press Book

· MCTS Self-Paced Training Kit (Exam 70-503):
Microsoft .NET Framework 3.0—Windows Communication Foundation

Microsoft E-Learning

· 6461AE: Visual Studio 2008:
Windows Communication Foundation (20 Hours)

Exam 70-503

 

8

Classroom Training

· 01: Learning Plan for Designing and Developing Enterprise Applications
Using the Microsoft .NET Framework 3.5 (Exam 70-565) (1 Forms)

Exam 70-565

MCPD: Enterprise Application Developer 3.5 on Visual Studio 2008

Note: 2.0 Track

Since the previous exam has no book at this time, you can also take the .NET 2.0 Track Instead take Exam ,Exam 70-529 and Exam 70-549 instead for 2.0 Certification.

 

MCPD: Enterprise Application Developer on Visual Studio 2005

 

SharePoint Certifications

   

9

Microsoft Press Books

· The Microsoft SharePoint Step by Step Kit:
Microsoft Windows SharePoint Services 3.0 Step by Step
and Microsoft Office SharePoint Designer 2007

Microsoft E-Learning

· 5403AE: MCTS (Exam 70-631):
Microsoft Windows SharePoint Services 3.0, Configuring (12 Hours)

Exam 70-631

MCTS: Microsoft Windows SharePoint Services 3.0 – Configuration

10

Microsoft Press Books

Inside Microsoft Office SharePoint Server 2007

Microsoft E-Learning

· 5404AE: MCTS (Exam 70-630):
Microsoft Office SharePoint Server 2007, Configuring (12 Hours)

· 3376AE: Implementing Enterprise Search Using
Sharepoint Technologies (8 Hours)

Exam 70-630

MCTS: Microsoft Office SharePoint Server 2007 – Configuration

11

Microsoft E-Learning

· 5392AE: Developing and Extending Microsoft Windows SharePoint
Services 3.0 with Visual Studio 2005 (12 Hours)

· 5385AE: Developing Solutions with Microsoft Windows SharePoint
Services 3.0 and Visual Studio 2005 (12 Hours)

Exam 70-541

MCTS: Microsoft Windows SharePoint Services 3.0 – Application Development

12

Microsoft E-Learning

· 6071AE: Developing Solutions with Microsoft Office SharePoint
Server 2007 and Visual Studio 2005 (12 Hours)

Exam 70-542

MCTS: Microsoft Office SharePoint Server 2007 – Application Development

 

Team Foundation Server Certification

   

13

Classroom Training

· 6215A: Implementing and Administering
Microsoft Visual Studio 2008 Team Foundation Server (2 Days)

Exam 70-510

MCTS: Microsoft Team Foundation Server: Configuration and Development

 

SQL 2008 Certifications

   

14

Microsoft E-Learning

· 6369AE: Implementing and Maintaining Microsoft SQL Server 2008 (16 Hours)

· 2778CE: MCTS (Exam 70-433): TS: Microsoft SQL Server 2008, Database Development (18 Hours)

Microsoft Press Books

· MCTS Self-Paced Training Kit (Exam 70-432):
Microsoft SQL Server 2008 - Implementation and Maintenance

Exam 70-432

MCTS: SQL Server 2008, Implementation and Maintenance

15

Classroom Training

· 01: Learning Plan for Designing, Optimizing and Maintaining a
Database Server Infrastructure
using SQL Server 2008 (Exam 70-450) (1 Forms)

Exam 70-450

MCITP: Database Administrator 2008

16

Microsoft E-Learning

· 2778CE: MCTS (Exam 70-433): TS: Microsoft SQL
Server 2008, Database Development (18 Hours)

Microsoft Press Books

· MCTS Self-Paced Training Kit (Exam 70-433):
Microsoft SQL Server 2008 - Database Development

Exam 70-433

MCTS: SQL Server 2008, Database Development

17

Classroom Training

· 01: Learning Plan for Designing Database Solutions and Data
Access using SQL Server 2008 (Exam 70-451) (1 Forms)

Exam 70-451

MCITP: Database Developer 2008

18

Microsoft Press Books

· MCTS Self-Paced Training Kit (Exam 70-448):
Microsoft SQL Server 2008 -
Business Intelligence Development and Maintenance

Exam 70-448

MCTS: SQL Server 2008, Business Intelligence Development and Maintenance

19

Microsoft Press Books

· Microsoft SQL Server 2008 Reporting Services Step by Step

· Microsoft SQL Server 2008 MDX Step by Step

Exam 70-452

MCITP: Business Intelligence Developer 2008

Sending Generic.List collection back to WCF ObservableCollection

Found a good article and helped with a problem I was having, trying to send a list of collection back to a WCF service that was set to accept Observable Collections. 

Source: http://smehrozalam.wordpress.com/2009/01/18/ienumerabletoobservablecollection/

In WPF/Silverlight, binding UI objects such as DataGrid or ListBox to collections is typically done using an ObservableCollectioninstead of the generic List object. This way, our UI is automatically synchronized since the observable collection provides event notification to WPF data binding engine whenever items are added, removed, or when the whole list is refreshed. The LINQ extension methods that return a collection actually return IEnumerable<T>. The .NET framework for Silverlight provides built-in extension methods to convert IEnumerable<T> to List<T> and Array<T> but there’s no method available to convert the collection to ObservableCollection<T>(WPF developers can simply use this constructor overload) . So here’s one you may find useful:

  1. Public Static Class CollectionExtensions
  2. {
  3.     public static ObservableCollection<T> ToObservableCollection<T>(this IEnumerable<T> enumerableList)
  4.     {
  5.         if (enumerableList != null)
  6.         {
  7.             //create an emtpy observable collection object
  8.             var observableCollection = new ObservableCollection<T>();
  9.  
  10.             //loop through all the records and add to observable collection object
  11.             foreach (var item in enumerableList)
  12.                 observableCollection.Add(item);
  13.  
  14.             //return the populated observable collection
  15.             return observableCollection;
  16.         }
  17.         return null;
  18.     }
  19. }

Extension methods are very powerful and I am planning to post an example demonstrating their potential.

I’ve converted the above example to VB.Net version for you to copy.

Public Shared Function ToObservableCollection(Of T)(ByVal enumerableList As IEnumerable(Of T)) As ObservableCollection(Of T)
    If enumerableList IsNot Nothing Then
        'create an emtpy observable collection object
        Dim observableCollection As New ObservableCollection(Of T)()

        'loop through all the records and add to observable collection object
        For Each item As T In enumerableList
            observableCollection.Add(item)
        Next

        'return the populated observable collection
        Return observableCollection
    End If
    Return Nothing
End Function

Now you can call your List and send it back as a ObservableCollection

Mapping a DataTable to an Object Class. Like a homemade Linq to SQL. Send over WCF to SilverLight

Application Foundation

An application I work has architecture in a way where we have a Class object that represents each table. So for example we might have a “Customer” table in the database. So our class would be something like..

Customer.vb class file…

Public Class Customer

    Private _FirstName As String = String.Empty
    Public Property FirstName() As String
        Get
            Return _FirstName
        End Get
        Set(ByVal value As String)
            _FirstName = value
        End Set
    End Property

    Private _LastName As String = String.Empty
    Public Property LastName() As String
        Get
            Return _LastName
        End Get
        Set(ByVal value As String)
            _LastName = value
        End Set
    End Property

End Class

In this class is a function to say list all customers, we call this “GetList” method. You might use another way to bring back a list of data. Ideally now we’d want to bring back Enumerable Lists, but the app was already structured for DataSets and DataTables. So I was trying to reuse what we had.

Customer.vb class file

Public Function GetList() As Data.DataTable
    Dim oDS As Data.DataSet
    Try
        oDS = DataAccess.SqlHelper.ExecuteDataset(_ConnectionString, Data.CommandType.StoredProcedure, "CustomerGetList")
        Return oDS.Tables(0)
    Catch ex As Exception
        Throw ex
    Finally
        oDS = Nothing
    End Try
End Function

So on our pages we might do something like this…

Default.aspx.vb

Protected Sub Button1_ClickSave()
    Dim oCustomer As New Customer
    oCustomer.FirstName = "Fred"
    oCustomer.LastName = "Mastro"
    oCustomer.SaveToDB()

    GridView1.DataSource = oCustomer.GetList()
    GridView1.DataBind()

    oCustomer = Nothing

End Sub

 

And this returns a nice DataTable and populates the grid. Great!

Problem Areas over WCF to SliverLight

I was working on a SilverLight application that would talk to an existing business application, to pull back and list records.  I had to use a Service, so I went with WCF since RIA.Net is not in production yet.  The problem was that DataTables can not be serialized and set over WCF to SilverLight.  So I tried messing with Linq to SQL to pull data back and populate classes I already had, but LinqTables are not serializable either, and instead of modifying all the Linq classes generated in my class I wanted to find an easier solution.

DataTable to List(Of Customer) Solution

I can across these two posts: Datatable to List of Objects Mapper and Creating datarow to object mapper and was amazed. Using reflection Chris Rock (lol) was able to read the properties of the object and map each column of the datatable to the desired property of the object. This is what I’m looking to do.  This would manually mimic Linq type functionality. The Bulk of the code is this

My Helper.vb class file

  1.  
  2. Public Class Helper
  3.  
  4.     Public Function MapDatarowToObject(Of T)(ByVal dr As DataRow) As T
  5.         Try
  6.  
  7.             If dr Is Nothing Then
  8.                 Return Nothing
  9.             End If
  10.  
  11.             Dim instance As T = Activator.CreateInstance(Of T)()
  12.  
  13.             Dim properties() As Reflection.PropertyInfo = instance.GetType().GetProperties()
  14.  
  15.             If (properties.Length > 0) Then
  16.                 For Each propertyObject As Reflection.PropertyInfo In properties
  17.  
  18.                     Dim valueSet As Boolean = False
  19.  
  20.                     For Each attributeObject As Object In propertyObject.GetCustomAttributes(False)
  21.  
  22.                         If attributeObject.GetType() Is GetType(MapperColumn) Then
  23.                             Dim columnAttributeObject As MapperColumn = CType(attributeObject, MapperColumn)
  24.  
  25.                             If (columnAttributeObject.ColumnName <> String.Empty) Then
  26.  
  27.                                 If dr.Table.Columns.Contains(columnAttributeObject.ColumnName) AndAlso Not dr(columnAttributeObject.ColumnName) Is DBNull.Value Then
  28.                                     propertyObject.SetValue(instance, dr(columnAttributeObject.ColumnName), Nothing)
  29.                                     valueSet = True
  30.  
  31.                                 End If
  32.  
  33.                             End If
  34.                         End If
  35.                     Next
  36.  
  37.                     If Not valueSet Then
  38.                         If dr.Table.Columns.Contains(propertyObject.Name) AndAlso Not dr(propertyObject.Name) Is DBNull.Value Then
  39.                             propertyObject.SetValue(instance, dr(propertyObject.Name), Nothing)
  40.                         End If
  41.                     End If
  42.  
  43.                 Next
  44.             End If
  45.  
  46.             Return instance
  47.         Catch ex As Exception
  48.             Throw ex
  49.         End Try
  50.     End Function
  51.  
  52.     Public Function MapDataTableToList(Of T)(ByVal dt As DataTable) As Collections.Generic.IList(Of T)
  53.         If dt Is Nothing Then
  54.             Return Nothing
  55.         End If
  56.  
  57.         Dim list As IList(Of T) = New List(Of T)
  58.  
  59.         For Each dr As DataRow In dt.Rows
  60.             list.Add(MapDatarowToObject(Of T)(dr))
  61.         Next
  62.  
  63.         Return list
  64.     End Function
  65.  
  66. End Class
  67.  
  68. <AttributeUsage(AttributeTargets.Property)> _
  69. Public Class MapperColumn
  70.     Inherits Attribute
  71.  
  72.     Private mColumnName As String
  73.  
  74.     Public Sub New(ByVal columnName As String)
  75.         mColumnName = columnName
  76.     End Sub
  77.  
  78.     Public Property ColumnName() As String
  79.         Get
  80.             Return mColumnName
  81.         End Get
  82.         Set(ByVal value As String)
  83.             mColumnName = value
  84.         End Set
  85.     End Property
  86.  
  87. End Class

Using Mapper in WCF

Now in my WCF Service methods I can just instantiate Customers like I always do in the normal application and apply the new Mapper method to get a List of the class objects.

WCFServiceMethods.vb file (which is code-behind to WCFServiceMethods.svc)

  1. Imports System.ServiceModel
  2. Imports System.ServiceModel.Activation
  3. Imports System.Runtime.Serialization 'For DataContract
  4. Imports System.Collections.Generic
  5.  
  6. <ServiceContract(Namespace:="")> _
  7. <ServiceBehavior(IncludeExceptionDetailInFaults:=True)> _
  8. <AspNetCompatibilityRequirements(RequirementsMode:=AspNetCompatibilityRequirementsMode.Allowed)> _
  9. Public Class WCFServiceMethods
  10.     <OperationContract()> _
  11.     Public Function GetCustomers() As Collections.Generic.List(Of Customer)
  12.         Dim oCustomer As New Customer
  13.  
  14.         Dim Customers As Collections.Generic.List(Of Customer)
  15.         Customers = Helper.MapDataTableToList(Of Customer)(oCustomer.GetList())
  16.  
  17.         oCustomer = Nothing
  18.         Return Customers
  19.  
  20.     End Function
  21. End Class

You’ll see in Line 15, I can take the DataTable and now create a List(Of Customer) object, which is serializable and send it over the wire.

Applying it in SilverLight or Other Application that uses your WCF Service

Assuming you referenced your WCF Service.. Now on my SilverLight app on a button click I can get the List of Customers and show it natively in a datagrid.

MainPage.xaml code-behind

Private Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnSearch.Click
    Dim oWCFProxy As New WCFService.WCFServiceClient

    AddHandler oWCFProxy.GetCustomers, AddressOf oWCFProxy_GetCustomersCompleted
    oWCFProxy.GetCustomersAsync()

    oWCFProxy = Nothing

End Sub

Private Sub oWCFProxy_GetCustomersCompleted(ByVal sender As Object, ByVal e As WCFService.GetCustomersCompletedEventArgs)
    Dim Customers As Collections.ObjectModel.Collection(Of oWCFProxy.Customer)
    Customers = e.Result

    DataGrid1.ItemsSource = Customers
End Sub

Problem Area With Mapper Casting Types and Solution

So with all that above you should have enough to re-create all this. Read through Chris’ posts because it does a good job of explaining the mapper.  I ran into a problem with the mapper though on line 39. Problem is when it tries to map data from the database, it all comes back as a string, and you don’t know until run-time what System.Type you need, so you can’t CType or DirectCast by using System.Type.GetType(), so I had to create a crappy function to Throw ex check every possible combination. This the best way? I sure hope it isn’t. Hope to find a better solution for it but was pressed for time.

So what was my crappy solution? I don’t even want to post it haha. I swapped out line 39 and 28 with the a call to this method of 1531 lines of code.

Private Sub TryCastTypeToPropertyType(ByRef propertyObject As Reflection.PropertyInfo, ByRef instance As Object, ByRef dr As DataRow, ByRef ColumnName As String)

Try
'Try to Default Types
propertyObject.SetValue(instance, dr(ColumnName), Nothing)
Catch exDefault1 As InvalidCastException
Try
'Try to String
propertyObject.SetValue(instance, CType(dr(ColumnName), String), Nothing)
Catch exString1 As InvalidCastException
'Try to Integer
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Integer), Nothing)
Catch exInt32a As ArgumentException
'Try to DateTime
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), DateTime), Nothing)
Catch exDate1 As ArgumentException
'Try to Decimal
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Decimal), Nothing)
Catch exDecimal1 As ArgumentException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
Catch exDecimal2 As InvalidCastException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
End Try
Catch exDate2 As InvalidCastException
'Try to Decimal
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Decimal), Nothing)
Catch exDecimal1 As ArgumentException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
Catch exDecimal2 As InvalidCastException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
End Try
End Try
Catch exInt32b As InvalidCastException
'Try to DateTime
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), DateTime), Nothing)
Catch exDate1 As ArgumentException
'Try to Decimal
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Decimal), Nothing)
Catch exDecimal1 As ArgumentException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
Catch exDecimal2 As InvalidCastException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
End Try
Catch exDate2 As InvalidCastException
'Try to Decimal
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Decimal), Nothing)
Catch exDecimal1 As ArgumentException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
Catch exDecimal2 As InvalidCastException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
End Try
End Try
End Try
Catch exString2 As ArgumentException
'Try to Integer
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Integer), Nothing)
Catch exInt32a As ArgumentException
'Try to DateTime
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), DateTime), Nothing)
Catch exDate1 As ArgumentException
'Try to Decimal
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Decimal), Nothing)
Catch exDecimal1 As ArgumentException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
Catch exDecimal2 As InvalidCastException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
End Try
Catch exDate2 As InvalidCastException
'Try to Decimal
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Decimal), Nothing)
Catch exDecimal1 As ArgumentException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
Catch exDecimal2 As InvalidCastException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
End Try
End Try
Catch exInt32b As InvalidCastException
'Try to DateTime
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), DateTime), Nothing)
Catch exDate1 As ArgumentException
'Try to Decimal
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Decimal), Nothing)
Catch exDecimal1 As ArgumentException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
Catch exDecimal2 As InvalidCastException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
End Try
Catch exDate2 As InvalidCastException
'Try to Decimal
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Decimal), Nothing)
Catch exDecimal1 As ArgumentException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
Catch exDecimal2 As InvalidCastException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
End Try
End Try
End Try
End Try
Catch exDefault2 As ArgumentException
Try
'Try to String
propertyObject.SetValue(instance, CType(dr(ColumnName), String), Nothing)
Catch exString1 As InvalidCastException
'Try to Integer
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Integer), Nothing)
Catch exInt32a As ArgumentException
'Try to DateTime
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), DateTime), Nothing)
Catch exDate1 As ArgumentException
'Try to Decimal
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Decimal), Nothing)
Catch exDecimal1 As ArgumentException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
Catch exDecimal2 As InvalidCastException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
End Try
Catch exDate2 As InvalidCastException
'Try to Decimal
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Decimal), Nothing)
Catch exDecimal1 As ArgumentException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
Catch exDecimal2 As InvalidCastException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
End Try
End Try
Catch exInt32b As InvalidCastException
'Try to DateTime
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), DateTime), Nothing)
Catch exDate1 As ArgumentException
'Try to Decimal
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Decimal), Nothing)
Catch exDecimal1 As ArgumentException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
Catch exDecimal2 As InvalidCastException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
End Try
Catch exDate2 As InvalidCastException
'Try to Decimal
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Decimal), Nothing)
Catch exDecimal1 As ArgumentException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
Catch exDecimal2 As InvalidCastException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
End Try
End Try
End Try
Catch exString2 As ArgumentException
'Try to Integer
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Integer), Nothing)
Catch exInt32a As ArgumentException
'Try to DateTime
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), DateTime), Nothing)
Catch exDate1 As ArgumentException
'Try to Decimal
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Decimal), Nothing)
Catch exDecimal1 As ArgumentException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
Catch exDecimal2 As InvalidCastException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
End Try
Catch exDate2 As InvalidCastException
'Try to Decimal
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Decimal), Nothing)
Catch exDecimal1 As ArgumentException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
Catch exDecimal2 As InvalidCastException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
End Try
End Try
Catch exInt32b As InvalidCastException
'Try to DateTime
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), DateTime), Nothing)
Catch exDate1 As ArgumentException
'Try to Decimal
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Decimal), Nothing)
Catch exDecimal1 As ArgumentException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
Catch exDecimal2 As InvalidCastException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
End Try
Catch exDate2 As InvalidCastException
'Try to Decimal
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Decimal), Nothing)
Catch exDecimal1 As ArgumentException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
Catch exDecimal2 As InvalidCastException
'Try to Double
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Double), Nothing)
Catch exDouble1 As ArgumentException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
Catch exDouble2 As InvalidCastException
'Try to Boolean
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Boolean), Nothing)
Catch exBoolean1 As ArgumentException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
Catch exBoolean2 As InvalidCastException
'Try To Date
Try
propertyObject.SetValue(instance, CType(dr(ColumnName), Date), Nothing)
Catch ex As Exception
Throw ex
End Try
End Try
End Try
End Try
End Try
End Try
End Try
End Try
End Sub

Maybe I’ll get lucky and someone will post up a “Oh you can just do this, which is new in .Net 3.5 or 4.0.. “ and I can get rid of this thing. But hey it works!

Resource: How to Consume WCF and ASP.Net Web Services in Silverlight

Casting Types in VB.Net and More

Source: Cheat Sheet - Casting in VB.NET and C#

Great little find, and since I’m a VB.Net whore, I’ll just post up the VB.Net version :)

Casting in VB.NET

  1. By default in VB, casting is automatically done for you when you assign objects to variables. The objects are then automatically casted to the variables' type.

    This behavior can be influenced by an option line on top of your code file:

    Option Strict On
    Option Strict Off

    When on, casting is strict and not automatic.

  2. Explicit casting can be done with the cast operator CType() or DirectCast():

    textbox = CType(obj, TextBox)
    textbox = DirectCast(obj, TextBox)


    The difference between the two keywords is that CType succeeds as long as there is a valid conversion defined between the expression and the type, whereas DirectCast requires the run-time type of an object variable to be the same as the specified type. If the specified type and the run-time type of the expression are the same, however, the run-time performance of DirectCast is better than that of CType. DirectCast throws an InvalidCastException error if the argument types do not match.

  3. Testing if an object is of a particular type, can be done with the TypeOf...Is operator:

    If TypeOf obj Is TextBox Then...
  4. Obtaining a System.Type object for a given type can be done with the GetType operator:

    Dim t As System.Type
    t = GetType(String)
    MessageBox.Show(t.FullName)
  5. Obtaining a System.Type object for a given object can be done with the GetType method:

    Dim t as System.Type
    t = obj.GetType()
    MessageBox.Show(t.FullName)

Now to build on and add one more of my own…

Get the type based on an arbitrary string.

System.Type.GetType("System.String")

Problem with this though is you can not use it to cast using CType or DirectCast. Looking at the CType Function..

typename - Any expression that is legal within an As clause in a Dim statement, that is, the name of any data type, object, structure, class, or interface.

You can only use types that are compiled and can’t use types that show up at runtime. So trying to use CType(obj, System.Type.GetType(“System.String”)) will only get you an error.  Array bounds cannot appear in type specifiers.

How to get around this? I have no freaking idea, yet. I’m think I might could create a custom type of my own and do something so that it converts to the proper method but for now I’ll just catch a few ArgumentExceptions and try different cast types then.

C# - Singleton Pattern vs. Static Classes

Link sent to me from Justin.. as we’ve been discussing using Singleton’s in Win Services for the previous post I talked about. I’ll convert to VB later.

Original Article: http://dotnet.dzone.com/news/c-singleton-pattern-vs-static-

By Sam Allen

Problem: Store some common data in a singleton or static class about your program in an object array, which you store in a class. It saves state between usages and stores some caches, and must be initialized only once and shared in many code locations. Making a new object each time would be expensive.

Solution

This article covers the differences between the singleton design pattern and the static keyword on C# classes. Static classes and singletons both provide sharing of redundant objects in memory, but they are very different in usage and implementation.

Introducing the Singleton Pattern

Our ideal solution is called the singleton design pattern. Here is an implementation of a singleton that I will use. As you know, a singleton is a single-instance object. It is highly efficient and very graceful. Singletons have a static property that you must access to get the object reference.

view source

print?

01./// <summary>

02./// Sample singleton object.

03./// </summary>

04.public sealed class SiteStructure

05.{

06. /// <summary>

07. /// Possible an expensive resource we need to only store in one place.

08. /// </summary>

09. object[] _data = new object[10];

10. /// <summary>

11. /// Allocate ourselves. We have a private constructor, so no one else can.

12. /// </summary>

13. static readonly SiteStructure _instance = new SiteStructure();

14. /// <summary>

15. /// Access SiteStructure.Instance to get the singleton object.

16. /// Then call methods on that instance.

17. /// </summary>

18. public static SiteStructure Instance

19. {

20. get { return _instance; }

21. }

22. /// <summary>

23. /// This is a private constructor, meaning no outsides have access.

24. /// </summary>

25. private SiteStructure()

26. {

27. // Initialize members, etc. here.

28. }

29.}

Static Class Example

In the following example, look carefully at how the static keyword is used on the class and constructor. Static classes may be simpler, but the singleton example has many important advantages, which I will elaborate on after this code block.

view source

print?

01./// <summary>

02./// Static class example. Pay heed to the static keywords.

03./// </summary>

04.static public class SiteStatic

05.{

06. /// <summary>

07. /// The data must be a static member in this example.

08. /// </summary>

09. static object[] _data = new object[10];

10. /// <summary>

11. /// C# doesn't define when this constructor is run, but it will

12. /// be run right before it is used most likely.

13. /// </summary>

14. static SiteStatic()

15. {

16. // Initialize all of our static members.

17. }

18.}

You can use static classes to store single-instance, global data. The class will be initialized at any time, but it is my experience that it is initialized lazily, meaning at the last possible moment. However, you lose control over the exact behavior of the class by using a static class.

Singleton Advantages

Singletons preserve the conventional class approach, and don't require that you use the static keyword everywhere. They may be more demanding to implement at first, but will greatly simplify the architecture of your program. Unlike static classes, we can use singletons as parameters or objects.

view source

print?

1.// We want to call a function with this structure as an object.

2.// Get a reference from the Instance property on the singleton.

3.{

4. SiteStructure site = SiteStructure.Instance;

5. OtherFunction(site); // Use singleton as parameter.

6.}

Interface Inheritance

In C#, an interface is a contract, and objects that have an interface must meet all of the requirements of that interface. Usually, the requirements of the interface are a subset of the object in question. Here is how we can use a singleton with an interface, which in the example is called ISiteInterface.

view source

print?

01./// <summary>

02./// Stores signatures of various important methods related to the site.

03./// </summary>

04.public interface ISiteInterface

05.{

06.};

07./// <summary>

08./// Skeleton of the singleton that inherits the interface.

09./// </summary>

10.class SiteStructure : ISiteInterface

11.{

12. // Implements all ISiteInterface methods.

13. // [omitted]

14.}

15./// <summary>

16./// Here is an example class where we use a singleton with the interface.

17./// </summary>

18.class TestClass

19.{

20. /// <summary>

21. /// Sample.

22. /// </summary>

23. public TestClass()

24. {

25. // Send singleton object to any function that can take its interface.

26. SiteStructure site = SiteStructure.Instance;

27. CustomMethod((ISiteInterface)site);

28. }

29. /// <summary>

30. /// Receives a singleton that adheres to the ISiteInterface interface.

31. /// </summary>

32. private void CustomMethod(ISiteInterface interfaceObject)

33. {

34. // Use the singleton by its interface.

35. }

36.}

Now we can reuse our singleton for any of the implementations of interface-conforming objects. There may be 1, 2, or 10. We don't need to rewrite anything over and over again. We store state more conventionally, use objects by their interfaces, and can use traditional object-oriented programming best practices.

Conclusion

Here we can reuse code and control object state much easier. This allows you greatly improved code-sharing, and a far cleaner body of code. With less code, your programs will usually have fewer bugs and will be easier to maintain. One good book about this topic is called C# Design Patterns and is written by Judith Bishop.