VS 2008 How to avoid "The type initializer for... threw an exception"-VBForums
Results 1 to 8 of 8

Thread: How to avoid "The type initializer for... threw an exception"

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2010
    Posts
    44

    How to avoid "The type initializer for... threw an exception"

    I just created this program 2 weeks ago, and stop doing for two weeks... before, it perfectly run and has no errors on all of my instance variable that i declared, though in is not finish...

    When I'm about to continue doing my project, this error suddenly appear,... Even my 'StrSQL' variable which I declare in my Module as follow:

    Code:
    Public strSQL as String
    and upon calling the variable it also has that error... same with this declarion inside my modGlobal module,

    Code:
        Public RoomWindow As New frmRoomWindow
        Public AccountReceivable As New frmAccRecLookUp
        Public GuestLookup As New frmGuestLookup
        Public ReservationLookup As New frmReservLookup
        Public AlterData As New frmAlterData
        Public Checkin As New frmCheckIn
        Public ManageAccount As New frmManageAccounts
    
        Public ucButton As New ucAA_Button
        Public usermain As New ucUserInformation
        Public room As New ucRoom
        Public paymenttype As New ucPaymentType
        Public idtype As New ucIDType
        Public customer As New ucCustomer
        Public company As New ucCompany
        Public charges As New ucChargeType
        Public accountrecord As New ucAccountRecord
    All of them suddenly has that error,...

    What would be the problem with this?... I'm stock with this problem...
    Does my Visual Studio 2008 has the problem?

  2. #2
    PowerPoster kevininstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    5,681

    Re: How to avoid "The type initializer for... threw an exception"

    You need to supply more details.

    What is the exact message in regards to the error? The more details the better readers can assist you.

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2010
    Posts
    44

    Re: How to avoid "The type initializer for... threw an exception"

    That's the only errors it show, along with name of the instance that I first declared in my Module,...

    Code:
    The type initializer for 'ucButton' threw an exception
    I tried to recreate the same form in my project that has this error with exact declaration of the variable and instances, and it runs fine...

  4. #4
    PowerPoster kevininstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    5,681

    Re: How to avoid "The type initializer for... threw an exception"

    Quote Originally Posted by jasluv View Post
    That's the only errors it show, along with name of the instance that I first declared in my Module,...

    Code:
    The type initializer for 'ucButton' threw an exception
    I tried to recreate the same form in my project that has this error with exact declaration of the variable and instances, and it runs fine...
    What is ucButton? Is it a standard button or a custom button?

  5. #5

    Thread Starter
    Member
    Join Date
    Jan 2010
    Posts
    44

    Re: How to avoid "The type initializer for... threw an exception"

    My mistakes... I replied wrong error message...

    this the right error message anyway..
    Code:
    The type initializer for 'HotelMngtSystem_SAD2_.modGlobal' threw an exception.
    The content of modGlobal procedure all the instances of my User Control and Public Variables, a Posted in my first post... all of it's content produces that kind of error...

  6. #6
    PowerPoster kevininstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    5,681

    Re: How to avoid "The type initializer for... threw an exception"

    My first thought is if everything worked two weeks ago and now to your knowledge nothing has changed I would begin by looking for a single line of code that does not seem right.

    For instance, when leaving the project last time (I have seen this happen) a key was entered upon exit on the current line.

    For instance, the current line was
    Dim Name as String

    Somehow it ended up as
    Dim Namse as String

    Which if global and used a lot could toss issues into other code and produce what I call a false positive exception where the actual reported exception is incorrect and another exception is there.

    Either way this is when using source control software is a huge plus as you can go back to a prior version of your project to before the problem.

  7. #7

    Thread Starter
    Member
    Join Date
    Jan 2010
    Posts
    44

    Re: How to avoid "The type initializer for... threw an exception"

    I already reviewed all of that... It really confused me why this happened, while in my other project that has the same declaration with this works perfectly and has nor errors..

  8. #8
    PowerPoster kevininstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    5,681

    Re: How to avoid "The type initializer for... threw an exception"

    Quote Originally Posted by jasluv View Post
    I already reviewed all of that... It really confused me why this happened, while in my other project that has the same declaration with this works perfectly and has nor errors..
    If you do not have a backup make one now.
    Make sure you have the proper framework selected, can not hurt to check
    Next start peeling away layers in an attempt to see if you can figure out what is the item causing the problem.

    At this point with this type of project it's all comes down to detective work.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.