We got a failing test because of some changes we made in RavenDB, and the underlying reason ended up being this code:
The problem was that the type that I was expecting did inherit from the right stuff. See this:
So something here is very wrong. I tracked this until I got to:
return RuntimeTypeHandle.CanCastTo(fromType, this);
And there is stopped. I work around this issue by using IsSubclassOf, instead of IsAssignableFrom.
The problem with IsAssignableFrom is that it is a confusing method. The parent is supposed to be the target, and the type you check is the parameter, but it is very easy to forget that and get confused. This worked for 99% of cases, because the single assembly we usually use also contained the RavenBaseApiController (which obviously can be assigned to itself), so that looked like it worked. IsSubclassOf is much nicer, but you need to understand that this won’t work for interfaces, or check direct equality. In this case, this was exactly what I needed, so that worked.