You´re trying to cast an object to something it´s not. Without code we can´t really help you.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.