Unable to cast object of type 'TYPE' to type 'TYPE'.

I've got a custom class and collection...I want to use them to databind a Grid, and persist the state using a Session variable.  However I keep getting the above error **Sometimes...

There will be times when it works fine, and times when it totally craps out.

System.InvalidCastException: Unable to cast object of type 'ApprovalCycleCollection' to type 'ApprovalCycleCollection'.

 

This should work fine, no?  I want a property to use in all my foreach loops

 

    public ApprovalCycleCollection NewApprovalCycle
    {
        get
        {
            if (Session["NewApprovalList"] == null)
                Session["NewApprovalList"] = new ApprovalCycleCollection();

            return (ApprovalCycleCollection)Session["NewApprovalList"];
        }
    }
  
0
stevescotthome
1/19/2009 7:15:24 PM
asp.net.getting-started 91979 articles. 4 followers. Follow

1 Replies
1249 Views

Similar Articles

[PageSpeed] 42

 May be this custom class is defined in multiple using namespaces in your code file.. Refer to this blog post.. It might be helpful

http://www.hanselman.com/blog/FusionLoaderContextsUnableToCastObjectOfTypeWhateverToTypeWhatever.aspx


Kumar Reddi
0
Kumar
1/19/2009 8:27:12 PM
Reply:

Similar Artilces:

Cast from type ''''DBNull'''' to type ''''String'''' is not valid.
How do I avoid getting this error: Cast from type ''''DBNull'''' to type ''''String'''' is not valid. I am trying to get values from the database into a form for updating using a Datareader, SQL is set to allow nulls for certain fields as they are not required but the only way I can get the form to display is by adding a space in SQL. Is there another way around this? Check if it is equal to DBNull.Value first and if it is, don't do the cast.Stanley Tan theSpoke Blog Where in the code does it need to go? I am using the following and it's the profile that isn't always requi...

Cannot convert type 'type' to 'type'
I am learning all of this, so I am still fresh, so please bear with me :)I have a page that has some txtboxes in it, simple registration form, and I have a button that will save those txt boxes to the db. I am using:- I am using Visual Web Developer 2008 Express Edition- C# When I try to compile the project I get error: Cannot convert type 'System.Web.UI.WebControls' to 'String' This is content of my web.config    <profile> <properties> <add name="FirstName"/> <add name="LasttName"/>...

Unable to cast object of type 'ProfileCommon' to type 'ProfileCommon'
I was getting this error out of nowhere. I had just uploaded my latest files to my remote server. When I ran locally again a few minutes later, I was suddenly getting the error: Unable to cast object of type 'ProfileCommon' to type 'ProfileCommon' I searched all over and could not find a fix. The error was coming from a line where I was trying to read a custom property off of the profile object. I went into the web.config file and changed: <profile enabled="true"> to <profile enabled="false">, and then back again. It worked fine after that. I thought to post this info for other...

Unable to cast object of type 'FormA' to type 'FormB'.
Hi,I have have a following error below when I try to reference the FormA  to FormB, It fails to cast the object. I'm working on VS2005 and have set ASP.NET v2.0.  Is this something related to the Assembly?  How do I fix this?  Thanks... private FormA mFormAPage; if (SearchFormA == "A") { mFormAPage = (FormA)Context.Handler; ....... }Error:  Unable to cast object of type 'ASP.FormA_aspx' to type 'FormB'. System.NullReferenceException was unhandled by user code  Message="Object reference not set to an instance...

Unable to cast object of type 'master1' to type 'master2'
Got a web site with two master pages.  Most of the pages use Master1 by default, however, occassionally I have to dynamically change to Master2 by setting the Page.MasterPageFile property to Master2.  In typical Microsoft fashion, this "kind of" works.  I can change the master file just fine, however, the application also calls code in the master file and this doesn't work!  Specifically, I have a public method called CheckSecurity() that is called by the entire application (lots of pages as well as more code, so I really don't want to move the co...

Unable to cast object of type 'CShoppingCartItem' to type 'CShoppingCartItem'
Dear All,            I have a simple shopping cart application. In one page I can run well my shopping cart even I come from other page to my viewcart it shows everything very well. My shopping cart is based on the session concept and class. So in the same page of viewcart I have a button checkout. So when I pressed it will take me to another page to regenerate my whole shopping cart. Here I can see the count value of my session is correct but when then I get an error as Unable to cast object of type 'CShoppingCartItem' to type '...

Unable to cast object of type 'System.Object[]' to type 'System.Data.DataView'.
I am tring to retieve a single node from my BLL code which retrieve one instane of Repot object:DataView dv = (DataView)objBoutPrep.Select();I am getting error:Unable to cast object of type 'System.Object[]' to type 'System.Data.DataView'. The BLL code returns onle one object and not a list of objects.Please help Client code: <asp:ObjectDataSource ID="objBoutPrep" runat="server" SelectMethod="GetRByID" UpdateMethod="UpdateT" TypeName="MB.K.BLL.G.Report"> <SelectParameters> <asp:Query...

How do I get around this error "Unable to cast object of type 'System.DBNull' to type 'System.String' "
I am using Visual Developer 2008 Express Edition for the first time, and I keep getting the following error below. The site allows anyone to enter with a valid username and password, but even when I logoff the site I get the same error....like the memory or database is not getting refreshed. I would think that when I initially compile the site that anything left in memory would be flushed out. Can someone please help me to figure this out. Thanks,Ramell P.S. The site is programmed using C#    Unable to cast object of type 'System.DBNull' to type 'System.String&...

Unable to cast object of type 'System.UInt32' to type 'System.String'?
Hi all,I'm trying to retrieve a column in my table (MySQL), this is the primary key of that table, and here is my code: public string GetAsocPKByUserName(string UserName) { MySqlConnection conn = new MySqlConnection(); MySqlCommand myCommand = new MySqlCommand(); string ASOC_PK = string.Empty; try { conn = new MySqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); conn.Open(); myCommand = new MySqlCommand("SELECT Distinct ASOC_PK FROM asso...

Unable to cast object of type 'ProfileCommon' to type 'ProfileCommon' with custom ProfileProvider
I have a fairly simple test right now and am comming across this error when ever I add a property of type 'Person' (Custom Class). I have a nother property of type Vendor that has no problem when I run the app with just this property. As soon as I add the Person Property I get the Error. One thing that I noticed is that ProfileProvider Intialize event gets triggered when I have the Person property and not when I have just the Vendor property. Any ideas would be appreciated. <profile defaultProvider="GlobalProfileProvider" enabled="true" > <providers> <add applicationName="P...

Unable to cast object of type 'System.DBNull' to type 'System.String'
I have received the following error when I am logged in as administrator.  I wanted to test the load event feature.  Allows me to load and save new event.  I can view event on location view page but when I try to link to "list or calender" view I receive this error "Unable to cast object of type 'System.DBNull' to type 'System.String'.  Debug highlights the <asp:HyperlinkID as errored line. Any assistance would be greatly appreciated Brian   <DayEventTemplate> <div style="padding: 3px;"> <asp:Hyper...

Unable to cast object of type 'System.DBNull' to type 'System.String'.
Hi there, If I add a new event and leave the description field empty the StarterKit seems to throw a big wobbly over the null values in my DB (SQL2000). Have I made a mistake in the installation or something? The problem lies in this line: SharedRoutines.truncate((string)Eval("description")) because description is Null. I want to sort this in this line and I don't want to reply on validators? This is a known issue reported in the Identified Bugs and Fixes for the ClubSite Starter Kit post. I don't think there is one definitive answer. Search on your error message and you'll fin...

Unable to cast object of type 'System.String' to type 'System.Array'
I really need to get this working! I have dimensioned fnames in line 2 to 200 slots. This code gets all the file names in a subdirectory and places them into an array. First files(), a dynamic array, gets the full path. Then line 9 splits it up into it's parts. I grab the last part (the filename) and store it into fnames. The message is  Unable to cast object of type 'System.String' to type 'System.Array'.  How do I get this to work?  Filenames is an array. Line 9 works. It takes a string (str) and converts it into the Array filenames. Why doesn't the n...

Unable to cast object of type 'System.String[]' to type 'System.IConvertible'.
hi expert   i try get the string from request.querystring("CID") from the error messege i know that is string[] (array) how to convert it to int32 and request.querystring("CID") is int value   Line 19: protected void ObjectDataSourceCarPicture_Inserting(object sender, ObjectDataSourceMethodEventArgs e) Line 20: { Line 21: e.InputParameters.Add("CID", Convert.ToInt32(Request.QueryString.GetValues("CID")) ); Line 22: // e.InputParameters.Add("CID", Convert.ToInt32( Convert.ToString( a Request.QueryString.GetValues("CID"))))); Line 23: ...

Web resources about - Unable to cast object of type 'TYPE' to type 'TYPE'. - asp.net.getting-started

Resources last updated: 12/18/2015 4:10:53 PM