Saturday, March 31, 2012

System.InvalidCastException

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?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" <MikeKansky@.discussions.microsoft.com> wrote in message
news:8DD38BB8-E1A6-4C92-8629-918A5F3FAC83@.microsoft.com...
>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?
>

0 comments:

Post a Comment