Reference page cast not working

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Error: Unable to cast object of type 'ASP.CompanyDirectory_aspx' to type
'CompanyDirectory'.

Code:
clsCompanyDirectory = (CompanyDirectory)Context.Handler;
getCompanyProfile(Strings.ConvertToInt(clsCompanyDirectory.CompanyIDValue));

Question: I have other pages with the exact same code and it does not
error. Why would this error? Am I missing something? How can the same page
not be cast on itself if it's the same type? Or maybe I need code that skips
the cast because it's already the page I need? This page is referenced in
the aspx file. Below is the same code except it it used in another area of
the site.

Code used in another page, *but works*:
// Create an instance of the page reference class to get incoming values
clsTranslatorDirectory = (TranslatorDirectory)Context.Handler
getTranslatorProfile(Strings.ConvertToInt(clsTranslatorDirectory.TranslatorIDValue));

Please explain the problem if you understand my issue. Thanks!
 
Same thing happened again. The exact code has been working for the past half
hour and when I reloaded the page I received this error:
Unable to cast object of type 'ASP.JobDirectory_aspx' to type 'JobDirectory'.

Note that this is for a different page with the same exact code:
// Create an instance of the page reference class to get incoming values
clsJobDirectory = (JobDirectory)Context.Handler;
getJobProfile(Strings.ConvertToInt(clsJobDirectory.JobIDValue));

Anyone know what's going on here? Please help as this issue holds me back
from development whenever it pops up... Thank you!
 
R said:
Same thing happened again. The exact code has been working for the past half
hour and when I reloaded the page I received this error:
Unable to cast object of type 'ASP.JobDirectory_aspx' to type 'JobDirectory'.

Note that this is for a different page with the same exact code:
// Create an instance of the page reference class to get incoming values
clsJobDirectory = (JobDirectory)Context.Handler;
getJobProfile(Strings.ConvertToInt(clsJobDirectory.JobIDValue));

Anyone know what's going on here? Please help as this issue holds me back
from development whenever it pops up... Thank you!

No idea here, but I wanted to add some depth to the discussion. I am
seeing the same problem periodically since I started upgrading to VS
2005 and ASP.NET 2.0. So maybe this is really an issue for an asp.net
forum.

-- Chris
 
Sure enough a search in the aspnet groups found something that might
help you:

http://groups.google.ca/group/micro...t+of+type+'ASP.&rnum=3&hl=en#d2276c25d7287180

The VS 2005 conversion tool did not properly convert my explicit @
Reference directive tags on the .ascx page, probably becuase no static
control of that type actually appears as a static control on the page.
It has been suggested that reference tags should be included on the
static page when using LoadControl() to load controls dynamically in
the code behind. To ensure that the tag is correct I actually drag the
user control on the design view of the page and then delete it.
 
Back
Top