The compiler sees the identifiers T2 and T and informs you that these types seem to be unrelated. This is absolutely correct, since they have nothing to do: there are no general restrictions that would affirm any relationship between them (I am not saying that it would be useful here, though :)).
Whether this is a good feature or not is controversial. Sometimes I would like it to be just a warning, but in most cases it is useful if it was a compilation error. The number of such castings in the birth classes is much less than the number of typos in the "normal" code :)
The solution is very simple. Just trick the compiler to know nothing about the source type, and it will skip checking the type hierarchy with the destination type:
T theTee = ...; object temp = (object)theTee; T2 teeTwo = (T2)temp; // ok! 'temp' is now seen as 'object'
or in one insert:
T2 teeTwo = (T2)(object)theTee;
Similarly, you can use dynamic (if available in your .Net version):
T theTee = ...; dynamic temp = theTee; T2 teeTwo = temp;
and oneliner should work too:
T2 teeTwo = (dynamic)theTee;
although I have never tried this since I think it is heavier than the cast-through-object method. However, I did not test the performance of object-dynamic approaches. Just a hunch.
source share