Author: harsha2212 | Posted on: 10/10/2008 6:44:46 PM | Views : 332

I'm using Page.LoadControl and it appears to throw an InvalidCastException randomly - which is to say that it works at times and sometimes it simply throws an exception. I tried searching around and discovered that this is a common problem, but could not find a solution. Some suggested that deleting temporary files could work. Didn't always work for me. In addition, I can't expect the users of the site to keep doing that

Everytime I faced this, simply making a minute change, even adding spaces to the code behind would solve the problem. I'm guessing that it would cause the page to recompile again.  Has anyone come across a similar problem before?

I will be trying to replace Page.LoadControl with Activator.CreateInstance to see if that stabilizes the code. However, since the problem is random, I can't be too sure.

Any concrete solutions would be helpful.
...

Go to the complete details ...