Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Annoying Cast Exception in .NET

  • 13-05-2008 8:31am
    #1
    Registered Users, Registered Users 2 Posts: 2,494 ✭✭✭


    Right how do I explain this one.....

    Business Object based on CBiz where CBiz implements the CRUD functionality. In the save depending on the type of object thats being saved we will call a class, lets say cPersonTest implementing a ITest interface, loaded via reflection, to do some work. The Work is carried out via a simple DoTest(CBiz ObjectToTest) Method as defined in ITest.

    So

    Person.Save()
    |
    V
    CBiz.Save()
    |
    V
    CBiz.LoadRuleViaReflection()
    |
    V
    CPersonTest.DoTest(CBiz ObjectToTest)

    I'm not doing anything to fancy here just loading up the assembly the class is contained in and creating an instance of the class. Then calling the DoTest method and passing in an object of type CBiz.

    Now the wierd problem I am hitting is the casting of the CBiz ObjectToTest back to type of Person within the CPersonTest Class. For some reason it wont let me cast to person, I get an error, and then mess around in the immediate window and depending on how the stars are alligned it might eventually cast for me. I can not help but wonder is this something got to do with the loading of the test class using reflection. Has any one come across the like before?


Comments

  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    Can you post the error trace?


  • Registered Users, Registered Users 2 Posts: 2,494 ✭✭✭kayos


    Have reworked the way I was doing things just to get around that problem for now. Once I get the chance I'll recreate the prob and post up the error details. But in all honesty its just your bog standard invalid cast exception.


Advertisement