473,406 Members | 2,620 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,406 software developers and data experts.

System.InvalidCastException

149 100+
Hi,

I have an InvalidCastException 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 ProcessRequestMain... +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 1823
rsdev
149 100+
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 Expert 512MB
Try using Convert.Toint32(id);
Jul 13 '07 #3
rsdev
149 100+
Thanks RadCeaser.

The problem was AutoEventWireUp. Glad to have a fix:)
Jul 13 '07 #4
rsdev
149 100+
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
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 ...
1
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...
4
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...
0
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...
1
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...
2
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) {...
1
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...
8
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...
8
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...
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
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
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,...
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...
0
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...
0
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...

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.