473,385 Members | 2,269 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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 2439
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 is exposed to client through remoting on Http...
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 out of the table are two integer fields, which I...
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 object of type 'System.Byte' to type 'System.String'. ...
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 the right direction. I am getting this error...
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 building the page. I have typecasted the lines as...
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 cast object of type 'System.Int32' to type...
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 that I got out of a hash table into a variable...
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 this code: Dim test3 As TextBox test3 =...
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 been placed in the App_Code folder. The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.