I have 2 different projects in my solution.
In one I have a class called MyClass1, and in the other I have MyClass2 These classes are identical in all but name.
In one project I have a list of Objects. During runtime the list gets filled with MyClass1 objects that we casted to an object.
At the end I want to cast each object in the list to a MyClass2 object.
Currently it throws an exception saying Unable to cast object of type MyClass1 to MyClass2.
My Code:
List<Object> _tempObjects = new List<Objects>();
foreach(Object myObjectInput in _tempObjects)
{
MyClass2 temp = (MyClass2) myObjectInput; // here is where it dies
}
The two classes are the same, just different names. I have also tried:
MyClass2 temp = myObjectInput as MyClass2;