Connecting Tech Pros Worldwide Forums | Help | Site Map

Error "Unable to cast object of type"-- but types are the same!

JackBlack
Guest
 
Posts: n/a
#1: Sep 21 '06
Hi, all! Need a little help tracking down a runtime error problem. I'm
getting this error:
"Unable to cast object of type 'myStruct[]' to type 'myStruct[]'... but the
two types are identical!

I have a class method that's building an array of user-defined structures
(see below), and returning that array to the calling routine. I'm getting
the error on that calling line.

The structure in both the webform and class are defined like this:
--------------------------------------------------------------------
Public Structure sttNavBarItems
Public strNavBarFeature As String
Public strNavBarACL As String
Public strNavBarURL As String
Public strNavBarParams As String
Public strNavBarTip As String
Public strNavBarPosition As Int16
End Structure

The array's are defined as such:
------------------------------------------------------------
Dim arrResult( ) as sttNavBarItems

Never seen this error before when both variables are of the same defined
type. What am I missing here?

Thanks!
Jack








GhostInAK
Guest
 
Posts: n/a
#2: Sep 21 '06

re: Error "Unable to cast object of type"-- but types are the same!


Hello JackBlack,

You define the struct in both the webform and the class file? Of course
you can't cast between them then. They are indeed different types. Define
the struct ONCE in one place that is accessible to both the web form and
the class.

-Boo
Quote:
Hi, all! Need a little help tracking down a runtime error problem.
I'm
getting this error:
"Unable to cast object of type 'myStruct[]' to type 'myStruct[]'...
but the
two types are identical!
I have a class method that's building an array of user-defined
structures (see below), and returning that array to the calling
routine. I'm getting the error on that calling line.
>
The structure in both the webform and class are defined like this:
--------------------------------------------------------------------
Public Structure sttNavBarItems
Public strNavBarFeature As String
Public strNavBarACL As String
Public strNavBarURL As String
Public strNavBarParams As String
Public strNavBarTip As String
Public strNavBarPosition As Int16
End Structure
The array's are defined as such:
------------------------------------------------------------ Dim
arrResult( ) as sttNavBarItems
>
Never seen this error before when both variables are of the same
defined type. What am I missing here?
>
Thanks!
Jack

JackBlack
Guest
 
Posts: n/a
#3: Sep 21 '06

re: Error "Unable to cast object of type"-- but types are the same!


Hmm... Since this is an ASP.Net application, there really isn't any place
that's accessible to both. The Class methods can't access the webform
methods, and a webform variable can't initialize a variable from a structure
defined in class.

What would you suggest?
Jack




"GhostInAK" <ghostinak@gmail.comwrote in message
news:be1391bf194168c8ab9996411334@news.microsoft.c om...
Quote:
Hello JackBlack,
>
You define the struct in both the webform and the class file? Of course
you can't cast between them then. They are indeed different types.
Define the struct ONCE in one place that is accessible to both the web
form and the class.
>
-Boo
>
Quote:
>Hi, all! Need a little help tracking down a runtime error problem.
>I'm
>getting this error:
>"Unable to cast object of type 'myStruct[]' to type 'myStruct[]'...
>but the
>two types are identical!
>I have a class method that's building an array of user-defined
>structures (see below), and returning that array to the calling
>routine. I'm getting the error on that calling line.
>>
>The structure in both the webform and class are defined like this:
>--------------------------------------------------------------------
>Public Structure sttNavBarItems
>Public strNavBarFeature As String
>Public strNavBarACL As String
>Public strNavBarURL As String
>Public strNavBarParams As String
>Public strNavBarTip As String
>Public strNavBarPosition As Int16
>End Structure
>The array's are defined as such:
>------------------------------------------------------------ Dim
>arrResult( ) as sttNavBarItems
>>
>Never seen this error before when both variables are of the same
>defined type. What am I missing here?
>>
>Thanks!
>Jack
>
>

JackBlack
Guest
 
Posts: n/a
#4: Sep 21 '06

re: Error "Unable to cast object of type"-- but types are the same!


Never minds, folks. Had the damned declaration in the wrong place. :) My
bad.

Jack


GhostInAK
Guest
 
Posts: n/a
#5: Sep 22 '06

re: Error "Unable to cast object of type"-- but types are the same!


Hello JackBlack,

I would suggest putting the struct in an assembly that both can access.

-Boo
Quote:
Hmm... Since this is an ASP.Net application, there really isn't any
place that's accessible to both. The Class methods can't access the
webform methods, and a webform variable can't initialize a variable
from a structure defined in class.
>
What would you suggest?
Jack
"GhostInAK" <ghostinak@gmail.comwrote in message
news:be1391bf194168c8ab9996411334@news.microsoft.c om...
>
Quote:
>Hello JackBlack,
>>
>You define the struct in both the webform and the class file? Of
>course you can't cast between them then. They are indeed different
>types. Define the struct ONCE in one place that is accessible to both
>the web form and the class.
>>
>-Boo
>>
Quote:
>>Hi, all! Need a little help tracking down a runtime error problem.
>>I'm
>>getting this error:
>>"Unable to cast object of type 'myStruct[]' to type 'myStruct[]'...
>>but the
>>two types are identical!
>>I have a class method that's building an array of user-defined
>>structures (see below), and returning that array to the calling
>>routine. I'm getting the error on that calling line.
>>The structure in both the webform and class are defined like this:
>>--------------------------------------------------------------------
>>Public Structure sttNavBarItems
>>Public strNavBarFeature As String
>>Public strNavBarACL As String
>>Public strNavBarURL As String
>>Public strNavBarParams As String
>>Public strNavBarTip As String
>>Public strNavBarPosition As Int16
>>End Structure
>>The array's are defined as such:
>>------------------------------------------------------------ Dim
>>arrResult( ) as sttNavBarItems
>>Never seen this error before when both variables are of the same
>>defined type. What am I missing here?
>>>
>>Thanks!
>>Jack

Closed Thread