473,666 Members | 2,281 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

System.InvalidC astException

149 New Member
Hi,

I have an InvalidCastExce ption which is completely puzzling me. I have checked all the members in the stored procedure against my data provider and seems to be ok. Also in the stack trace it says ProcessRequestM ain... +3742??

Here's the error;

Expand|Select|Wrap|Line Numbers
  1. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
  2.  
  3. Exception Details: System.InvalidCastException: Specified cast is not valid.
  4.  
  5. Source Error: 
  6.  
  7.  
  8. Line 126:        private static ComponentData DisplayComponent(IDataReader reader)
  9. Line 127:        {
  10. Line 128:            ComponentData component = new ComponentData(
  11. Line 129:               null, 
  12. Line 130:               (int)reader["section_id"],
  13.  
  14.  
  15. Source File: c:\Documents and Settings\Me\Desktop\tests\TMG_test\App_Code\DAL\ComponentData.cs    Line: 128 
  16.  
  17. Stack Trace: 
  18.  
  19.  
  20. [InvalidCastException: Specified cast is not valid.]
  21.    TMG.DAL.ComponentData.DisplayComponent(IDataReader reader) in c:\Documents and Settings\Me\Desktop\tests\TMG_test\App_Code\DAL\ComponentData.cs:128
  22.    TMG.DAL.ComponentData.GetComponentById(String pageId) in c:\Documents and Settings\Me\Desktop\tests\TMG_test\App_Code\DAL\ComponentData.cs:120
  23.    TMG.BLL.Components.ComponentInfo.GetComponentFromCache(String pageId) in c:\Documents and Settings\Me\Desktop\tests\TMG_test\App_Code\BLL\Components\ComponentInfo.cs:118
  24.    TMG.BLL.Components._components_featureComponent.Page_Load(Object sender, EventArgs e) in c:\Documents and Settings\Me\Desktop\tests\TMG_test\_components\featureComponent.ascx.cs:20
  25.    System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +13
  26.    System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +45
  27.    System.Web.UI.Control.OnLoad(EventArgs e) +80
  28.    System.Web.UI.Control.LoadRecursive() +49
  29.    System.Web.UI.Control.LoadRecursive() +132
  30.    System.Web.UI.Control.LoadRecursive() +132
  31.    System.Web.UI.Control.LoadRecursive() +132
  32.    System.Web.UI.Control.LoadRecursive() +132
  33.    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3742

Any help would be appreciated.
Jul 13 '07 #1
4 1841
rsdev
149 New Member
Found the answer in another forum, so thought I'd share.

The problem was in a user control that I was populating with data in Visual Web Developer 2005 the page automatically sets AutoEventWireUp to true. This needs to be set to false otherwise it loads before the page_load event.

Cheers.
Jul 13 '07 #2
radcaesar
759 Recognized Expert Contributor
Try using Convert.Toint32 (id);
Jul 13 '07 #3
rsdev
149 New Member
Thanks RadCeaser.

The problem was AutoEventWireUp . Glad to have a fix:)
Jul 13 '07 #4
rsdev
149 New Member
Ha!

I was being completely stupid:)

AutoEventWireUp just turned of the page_load function so no wonder the error went away.

The actual problem was a (bool)reader which I had entered into the DB as a string value=True rather than bit.

So now it's solved.
Jul 13 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
3682
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);
1
4881
by: Hifni Shahzard | last post by:
Hi, I got a stored procedure, where it returns a value. But if I execute it. It gives an error as "Invalid cast from System.Int32 to System.Byte.". To make clear how do I execute this, below I'm specifiying my code: The Code used in Visual Studio: Function GetRank(ByVal ID As Integer, ByVal Comp As String, ByVal Sec As String, ByVal iDate As Date) As String 'Dim Ret As Integer
4
2654
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:
0
623
by: QA | last post by:
I am using a Business Scorecard Accelarator in a Sharepoint Portal 2003 using SQL Server 2005 I am getting the following error: Error,5/7/2005 10:50:14 AM,580,AUE1\Administrator,"Specified cast is not valid.","Microsoft.BusinessIntelligence.Scorecard.ScorecardException: Specified cast is not valid. ---> Microsoft.BusinessIntelligence.Scorecard.ScorecardException: Specified cast is not valid. ---> System.InvalidCastException: Specified...
1
18170
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
2
13579
by: John Smith | last post by:
I'm writing webervice client using .Net 2.0. I have this class: public class MyWebService : SoapHttpClientProtocol { public XmlDocument validate(string url, XmlDocument xmlDocument) { this.Url = url;
1
5163
by: Ratz | last post by:
Hello everyone! I'm new to this Forum! I've spent about 56 hours trying to solve a .NET VB Runtime error while Using a program.Ive contacted the developer of the program and he could not figure out why i'm getting these errors! SO i have come here for the Help from the GURUS! here is one message that pops up! See the end of this message for details on invoking just-in-time (JIT) debugging instead of this dialog box. **************...
8
4264
by: Gamma | last post by:
I'm trying to inherit subclass from System.Diagnostics.Process, but whenever I cast a "Process" object to it's subclass, I encounter an exception "System.InvalidCastException" ("Specified cast is not valid"). How do I fix it ? using System.Diagnostics; .. .. class NewProcess: Process {
8
5758
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'
0
8781
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8550
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
8639
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
7385
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
4198
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
4366
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2769
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
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1772
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.