Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Annoying Cast Exception in .NET

  • 13-05-2008 09: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