473,888 Members | 1,378 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Specified cast is not valid

1 New Member
Thank for your answer. :-)
Specified cast is not valid.
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.

Exception Details: System.InvalidC astException: Specified cast is not valid.

Source Error:


Line 271: Microsoft.Web.U I.WebControls.T reeNode iNode = null;
Line 272:
Line 273: iNode = (Microsoft.Web. UI.WebControls. TreeNode) N;
Line 274:
Line 275: foreach ( Microsoft.Web.U I.WebControls.T reeNode tempNode in iNode.Nodes )


Source File: c:\inetpub\wwwr oot\payroll_cs\ frmmenu.aspx.cs Line: 273

Stack Trace:


[InvalidCastExce ption: Specified cast is not valid.]
Payroll_CS.frmM enu.CheckEmptyN ode(Object N) in c:\inetpub\wwwr oot\payroll_cs\ frmmenu.aspx.cs :273
Payroll_CS.frmM enu.Page_Load(O bject sender, EventArgs e) in c:\inetpub\wwwr oot\payroll_cs\ frmmenu.aspx.cs :106
System.Web.UI.C ontrol.OnLoad(E ventArgs e) +67
System.Web.UI.C ontrol.LoadRecu rsive() +35
System.Web.UI.P age.ProcessRequ estMain() +731
Expand|Select|Wrap|Line Numbers
  1. call CheckEmptyNode (treeview)
  2.  
  3.  
  4. public void CheckEmptyNode( Object N ) 
  5.         {             
  6.             Microsoft.Web.UI.WebControls.TreeNode menuNode = null; 
  7.             Microsoft.Web.UI.WebControls.TreeNode iNode = null;
  8.  
  9.             iNode = (Microsoft.Web.UI.WebControls.TreeNode) N;
  10.  
  11.             foreach ( Microsoft.Web.UI.WebControls.TreeNode tempNode in iNode.Nodes ) 
  12.             { 
  13.                 menuNode = tempNode;                
  14.                 if ( menuNode.Nodes.Count > 0 ) 
  15.                 { 
  16.                     CheckEmptyNode( menuNode ); 
  17.                 } 
  18.                 else 
  19.                 { 
  20.                     if ( menuNode.NavigateUrl.Trim() == "" ) 
  21.                     {                         
  22.                         itemNode.Nodes.Remove( menuNode ); 
  23.  
  24.                         if ( itemNode.Nodes.Count > 0 ) 
  25.                         { 
  26.                             CheckEmptyNode( N ); 
  27.                         }                         
  28.                         return;                         
  29.                     }                     
  30.                 }                 
  31.             }            
  32.         }
  33.  
May 20 '09 #1
2 8806
Curtis Rutland
3,256 Recognized Expert Specialist
From a quick glance, I'd say that you're passing an Object to your method that can't be cast as a Microsoft.Web.U I.WebControls.T reeNode.

That's the only cast you're doing, and the error message says "invalid cast."
May 20 '09 #2
Plater
7,872 Recognized Expert Expert
Indeed, N is not a Microsoft.Web.U I.WebControls.T reeNode nor a class that derives from Microsoft.Web.U I.WebControls.T reeNode.

OR Whats contained in N.Nodes is not garunteed to be reducable to a Microsoft.Web.U I.WebControls.T reeNode
May 21 '09 #3

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

Similar topics

0
3645
by: Tao | last post by:
I just upgraded .NET framework to 1.1 and VS.Net to 2003 version and tried to test it out. I created an ASP.NET project using the wizard and tried to run it by hitting "F5". I got an exception: "Specified cast is not valid." The only thing i put there was a "test this." inside the form. What might be the problem here? Thanks in advance. The Exception:
4
7046
by: Tyro | last post by:
Can someone shed some light on my error here? Thanks! Specified cast is not valid. Exception Details: System.InvalidCastException: Specified cast is not valid. Source Error: Stack Trace:
3
10522
by: PK9 | last post by:
I am looking for assistance in pinpointing the cause of the following exception. I am getting a "Specified Cast is not valid" exception on my page. I am trying to populate a datagrid. One of my columns is a template column where I'd like to evaluate the data brought back from the db and populate the column with a "Y" or "N" depending on the value in the db. Here is the code that is causing it as well as the error (below). ERROR...
2
3097
by: Fabian | last post by:
Hi, I work with asp.net 2.0 and I have a intermittent error, only happens a few times a day. In the page I evaluate a Query String and then I get data form a database. The code snipped: try {
3
2189
by: VB Programmer | last post by:
I am setting up forms authentication. In my code I keep getting this error. Any ideas? Error.... Server Error in '/LandOLots' Application. --------------------------------------------------------------------------------
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...
0
1632
by: Alan Z. Scharf | last post by:
this question in datagrid group for several days with no repsonse. I'm hoping for an answer her because of greater activity in this group. No cross-posting intended. Thanks. ----------------------------------------------------------- Server VS.NET 2003 SQLServer 2000 IIS 66.0
8
4279
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 {
3
12446
by: =?Utf-8?B?UGF1bCBQcmV3ZXR0?= | last post by:
I'm attempting to use LINQ to insert a record into a child table and I'm receiving a "Specified cast is not valid" error that has something to do w/ the keys involved. The stack trace is: ====================== Message: Specified cast is not valid. Type: System.InvalidCastException Source: System.Data.Linq TargetSite: Boolean TryCreateKeyFromValues(System.Object, V ByRef)
0
11185
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
10887
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
10439
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
9597
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
7990
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
7148
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
5824
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...
1
4642
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
3252
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.