473,890 Members | 1,410 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 strNavBarFeatur e As String
Public strNavBarACL As String
Public strNavBarURL As String
Public strNavBarParams As String
Public strNavBarTip As String
Public strNavBarPositi on 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 2468
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 strNavBarFeatur e As String
Public strNavBarACL As String
Public strNavBarURL As String
Public strNavBarParams As String
Public strNavBarTip As String
Public strNavBarPositi on 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*******@gmai l.comwrote in message
news:be******** *************** ***@news.micros oft.com...
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 strNavBarFeatur e As String
Public strNavBarACL As String
Public strNavBarURL As String
Public strNavBarParams As String
Public strNavBarTip As String
Public strNavBarPositi on 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*******@gmai l.comwrote in message
news:be******** *************** ***@news.micros oft.com...
>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 strNavBarFeatur e As String
Public strNavBarACL As String
Public strNavBarURL As String
Public strNavBarParams As String
Public strNavBarTip As String
Public strNavBarPositi on 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
7392
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 channal hosting into IIS. There is a class B which is also available through remoting hosted on IIS on the same URI. B creates new of A inside a function. It succeed and able to create instance of A inside B first time. But it failes in 2nd attempt when...
5
1903
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 am trying to cast as strings so they can be displayed in a Literal control. I am using the following code (heavily edited for clarity) ... if (dtrDilemmas.Read()) {
3
13023
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'. here is the code that I used to create a table and then add columns to it later, later I populate the rows in the table.
0
1581
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 after converting to .NET 2.0. Unable to cast object of type 'Oracle.DataAccess.Client.OracleCommand' to type 'System.Data.Common.DbCommand'
0
1634
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 follows: ((StyleSheetProvider)this.Page).GetStyleSheetPath(); Is there some different way of typecasting that needs to be done in vs2005? Thanks in advance.
3
10264
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 'System.String'.
10
2550
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 of type Foo.Bar. Foo.Bar data = (For.Bar)input; Thanks,
9
6414
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 = CType(e.Item.FindControl("edit_name"), TextBox)
1
2352
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 web.config has been updated with the necessary section. Using System.Web.Configuration.WebConfiguration.GetSection(), the config information is returned without any issues when the GetSection is set to an object. When the object is casted explicitly...
0
9978
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10460
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9625
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7169
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5845
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6041
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4674
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4270
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3275
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.