473,890 Members | 1,438 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 1077

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

Similar topics

3
2666
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
883
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
3704
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
2670
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
1223
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
18228
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
1829
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
5783
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
2165
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
4980
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
9979
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
11234
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...
1
10925
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10467
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
7171
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
5854
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
6052
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4682
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
3
3282
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.