473,813 Members | 3,361 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

InvalidCastExce ption when type-casting arrays

I have a set of business object classes built from the typed dataset tool in
Visual Studio. Since the individual objects (such as the Order object, for
example) inherit from DataRow, a common requirement is to cast an array of
DataRows to an array of Orders. But I keep getting InvalidCastExce ptions
when I do this, for example:

Dim orders As Order() = CType(RowsAffec ted, Order())

In this example, RowsAffected returns an array of DataRows after copying
them from the ArrayList where they're collected:

Public ReadOnly Property RowsAffected() As DataRow()
Get
Dim rows() As DataRow
If m_RowsAffected. Count > 0 Then 'm_RowsAffected is an
ArrayList
ReDim rows(m_RowsAffe cted.Count - 1)
m_RowsAffected. CopyTo(rows)
Else
ReDim rows(-1)
End If
Return rows
End Get
End Property

I am getting this exception even when the number of rows affected is higher
than 0. When I break into the code, I can interrogate CType(RowsAffec ted,
Order()) in the Immediate window and get the expected result, that is:

?CType(RowsAffe cted, Order())
{Length=1}
(0): {MyAssembly.Dat aObjects.Order}

This seems a lot like a bug to me. Am I missing something?

Any insight is appreciated. Thanks.

Regards,

Jon
Nov 20 '05 #1
0 1075

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

Similar topics

3
2664
by: WangHF | last post by:
hi , I had asked this question serveral days ago, but it's still unresolved. And I have found some new things. this error just occured sometimes,not always. the code like this:(It's running in a VS IED Add-In.) public static Mapping Deserialize(string strXmlFilePath) { XmlSerializer s = new XmlSerializer(typeof(Mapping));
0
881
by: che | last post by:
Hi all, I am working with XSD for a while using C# objects ( XmlSchemaCollection , XmlValidatingReader) and have met this problem: Current code demonstrates the problem: <xs:schema ...>
1
3700
by: bob scola | last post by:
I have a csharp, VS 2003 solution for a winform application The application uses an object called a "matter" and the class is defined in matter.cs. I can load matter objects into a combobox Matter matters= v.Matters; comboBox1.Items.AddRange(matters);
4
2666
by: DOTNET | last post by:
Hi, Anybody help me regarding this error: I am assigning the values to the session variables when the button is clicked and passing these session variables to the next page and when I am printing these session variables they are printing. After that I am assigning these things in hidden object and in the form submit action I am receiving these hidden values like the following:
2
1221
by: JPerrin | last post by:
I'm attempting to create a generic data access layer that can load any assembly that has objects implementing the "IDb..." interfaces. Everything is working perfectly when I use a SqlConnection, however when I attempt to use a MySqlConnection and cast it to an IDbConnection I'm getting an InvalidCastException, even though the MySqlConnection class implements the IDbConnection interface. Here's a snippet from my code: ------ if(...
1
18215
by: Marc | last post by:
Hi! I'm working with a C# client that calls a php web service. I've created a wrapper to call the service using .NET wsdl tool (adding a web reference). The call to the server works fine, it is serialized correctly, and the server returns a response (I've captured the response and it's correct!) but when the .NET deserialize this response, it throws the exception "System.InvalidOperationException: There is an error in XML
1
1827
by: BabuMan | last post by:
Hi, I have a FormView control on a page which is bound to a SQLDataSource table. Everything works fine except for the "Update". I get an InvalidCastException. The problem only seems to surface when I have a 'datetime' column in the table. I tested this with a very simple sample table. As long as there is no datetime column either in the table or on the form, all are peachy. Here is the code, in case somebody can figure it out. I...
8
5781
by: =?Utf-8?B?YXVsZGg=?= | last post by:
i trying to collect windows services. i'm getting inconsistencies. the collection works every time locally. but remote collection yields different result depending on my lab environment. 1) in the same domain i start the collection on the remote machine i can get some 19 services without a problem then it will fail with: 'wmiService.ClassPath' threw an exception of type 'System.InvalidCastException'
2
2163
by: Don Miller | last post by:
I use a Session variable to store a custom object (all properties contain strings) between postbacks. On occasion, mostly when I change and save code, when I refresh the web page to see the changes, I get an error: "System.InvalidCastException was unhandled by user code -Unable to cast object of type 'QueryParameters' to type 'QueryParameters'" in the function below which is called during Page_Load (_queryParameters =...
6
4975
by: dgleeson3 | last post by:
Hello All I have VB code (.Net 2005) reading from an SQL server 2005 database. Im getting InvalidCastException when doing reader.GetInt32(0) Im simply reading an int from a simple database. It has two columns, User and Tel number. User is filled with 1,2,3 and tel number has 3 telephone numbers. The User data column is specified as (PK, int, not null) in MS SQL
0
9734
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
9607
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10669
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10140
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
9224
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...
1
7684
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6897
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
5569
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...
2
3885
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.