Monday, January 22, 2007

Solving Unable to cast object of type 'ProfileCommon' to type 'ProfileCommon' error

I uncovered yet another strange behavior of ASP.NET which was mentioned by Alex Thissen at http://www.alexthissen.nl/blogs/main/archive/2005/05/31/asp-net-2-0-need-to-know-thingies-for-beta2.aspx.

Although Alex mentioned this to be a problem with Beta2, it can also occur on the relase version, e.g. Microsoft .NET Framework Version:2.0.50727.91; ASP.NET Version:2.0.50727.210.

I got this error:
Unable to cast object of type 'ProfileCommon' to type 'ProfileCommon'.
[InvalidCastException: Unable to cast object of type 'ProfileCommon' to type 'ProfileCommon'.] MasterPageCls.get_Profile() +67
MasterPageCls.SetDefaultZoningSystem() in c:\inetpub\...\MasterPage.vb:33
MasterPageCls.InitZSID() in c...\MasterPage.vb:152
MasterPageCls.Page_Load1(Object sender, EventArgs e) in ...\MasterPage.vb:186
System.Web.UI.Control.OnLoad(EventArgs e) +99 System.Web.UI.Control.LoadRecursive() +47 System.Web.UI.Control.LoadRecursive() +131
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061

The resolution? Simply making a simple change in web.config for the application and saving it again, which worked. Referring to an earlier post on my blog, this time, clearing the temporary folder did not resolve the problem.

I find this error strange and a bit confusing. If the type has the same name, why can't I cast it? And what does an invalidated web.config have to do a class in the membership provider anyway?

3 comments:

Anonymous said...

I had this same issue, but simply making a change in the web.config did not do the trick. What I did was wipe out the project folder inh the 2.0.50727 Temporary ASP.NET Files. restarted my project and it worked fine. So, for those that find themselves in this situation, now you have another method you can try.

Plamen Kasabov said...

You can solve this problem by set profile to be enabled="false" in your web.config, then refresh asp page and return profile to be enabled="true" and refresh again. Very simple and stupid, but works fine. Try it

Anonymous said...

Hello,

I mostly visits this website[url=http://www.weightrapidloss.com/lose-10-pounds-in-2-weeks-quick-weight-loss-tips].[/url]Lots of good information here aspxperience.blogspot.com. I am sure due to busy scedules we really do not get time to care about our health. Let me present you with one fact here. Research presents that almost 70% of all USA grownups are either obese or overweight[url=http://www.weightrapidloss.com/lose-10-pounds-in-2-weeks-quick-weight-loss-tips].[/url] Therefore if you're one of these citizens, you're not alone. In fact, most of us need to lose a few pounds once in a while to get sexy and perfect six pack abs. Now next question is how you can achive quick weight loss? You can easily lose with with little effort. You need to improve some of you daily habbits to achive weight loss in short span of time.

About me: I am webmaster of [url=http://www.weightrapidloss.com/lose-10-pounds-in-2-weeks-quick-weight-loss-tips]Quick weight loss tips[/url]. I am also mentor who can help you lose weight quickly. If you do not want to go under painful training program than you may also try [url=http://www.weightrapidloss.com/acai-berry-for-quick-weight-loss]Acai Berry[/url] or [url=http://www.weightrapidloss.com/colon-cleanse-for-weight-loss]Colon Cleansing[/url] for fast weight loss.