472,342 Members | 1,359 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,342 software developers and data experts.

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

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



Sep 21 '06 #1
4 2350
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
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

Sep 21 '06 #2
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" <gh*******@gmail.comwrote in message
news:be**************************@news.microsoft.c om...
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
>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


Sep 21 '06 #3
Never minds, folks. Had the damned declaration in the wrong place. :) My
bad.

Jack
Sep 21 '06 #4
Hello JackBlack,

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

-Boo
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" <gh*******@gmail.comwrote in message
news:be**************************@news.microsoft.c om...
>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
>>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

Sep 22 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Pankaj Jain | last post by:
Hi All, I have a class A which is derived from ServicesComponent to participate in automatic transaction with falg Transaction.Required. Class A...
5
by: Alan Silver | last post by:
Hello, I have an ASP.NET page where I am grabbing an SqlDataReader and using it to populate some controls on the form. Amongst the fields pulled...
3
by: Imran Aziz | last post by:
Hello All, I am getting the following error on our production server, and I dont get the same error on the development box. Unable to cast...
0
by: sam | last post by:
Hi: I am not sure if this is the right place to post this question. Please let me know if it is not and I appreciate if someone could point me in...
0
by: hlyall1189 | last post by:
Hi, I recently started upgrading some of my old vs 2003 apps to vs 2005 and used the conversion tool but now i get the following error after...
3
by: keithb | last post by:
What could be causing this? this code: String Com = ""; if (Com != (String)rw.ItemArray) fails at runtime with the error message: Unable to...
10
by: mypetrock | last post by:
Has anyone run into this error message? Unable to cast object of type 'Foo.Bar' to type 'Foo.Bar'. I'm trying to cast an object of type Foo.Bar...
9
by: Jim in Arizona | last post by:
I get this error: Unable to cast object of type 'System.Web.UI.HtmlControls.HtmlInputText' to type 'System.Web.UI.WebControls.TextBox'. Using...
1
by: =?Utf-8?B?U2NvdHQ=?= | last post by:
Hello, Using VS2008 in a C# web service application, a class has been created that inherits from the ConfigurationSelection. This class file has...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.