Re: System.InvalidCastException

Discussion in 'ASP .Net' started by Karl Seguin, Jan 17, 2007.

  1. Karl Seguin

    Karl Seguin Guest

    A class can't exist in two places at the same time. Just because they have
    the same name and share all the same members, doesn't make them the same.

    As far as .NET is concerned, you might as well be trying to cast a textbox
    to a database connection.

    This class should be defined in your business layer ONLY...and your aspx
    page should create an instance of THAT class.

    Karl

    --
    http://www.openmymind.net/
    http://www.codebetter.com/


    "Mike Kansky" <> wrote in message
    news:...
    >I have UI Page.aspx which has this class:
    > PAGE.ASPX
    >
    > private class Blah
    > public bVar as boolean
    > end class
    >
    >
    > On page load this class is added to the collection ColBlah and sent to the
    > function in business layer which has identical class defined.
    >
    > BusLayer.vb
    >
    > private class Blah
    > bVar as boolean
    > end class
    >
    > class BusLayer
    > Public function Process(oCol as collection)
    > dim oObject, oBlah as Blah
    > for each oObject in oCol
    > oBlah=CType(oObject,Blah)
    > next oCol
    >
    > end class
    >
    > the line oBlah=CType(oObject,Blah) generates the following exception
    > System.InvalidCastException
    >
    > Why? Anybody?
    >
     
    Karl Seguin, Jan 17, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Floela
    Replies:
    3
    Views:
    578
    Jon Skeet
    Jul 10, 2003
  2. Arjen
    Replies:
    1
    Views:
    7,775
    Carl Prothman [MVP]
    Aug 6, 2003
  3. Miguel Angel Dinelli
    Replies:
    1
    Views:
    448
    Chris Jackson
    Nov 13, 2003
  4. Roy Lawson
    Replies:
    12
    Views:
    5,201
  5. Brian Conway

    System.InvalidCastException

    Brian Conway, May 18, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    395
    Brian Conway
    May 18, 2004
Loading...

Share This Page