Collider.Raycast is complaining that my ray does not have a normalized direction

I have a bit of code that looks like this. I am investigating behavior when raycasts originate inside colliders, so assume that “point” may be inside the collider.

public static bool foo (Vector3 point, Collider collider) {
    Vector3 vectorToCollider = collider.ClosestPointOnBounds(point) - point;
    vectorToCollider.Normalize();
    Ray rayToCollider = new Ray(point, vectorToCollider);
    RaycastHit dummyHit = new RaycastHit();
    if (!collider.Raycast(rayToCollider, out dummyHit, float.PositiveInfinity)) {
        return false;
    } else {
        return true;
    }
}

I am running into problems because the actual collider.Raycast call is causing this method to break, because apparently vectorToCollider is not normalized. Specifically, I’m seeing:

!isNormalized(ray.GetDirection ())

I’m very confused, since I believe I am correctly normalizing vectorToCollider before passing it in as an argument to the Ray constructor. I’ve also tried using vectorToCollider.normalized instead, but I’ve experienced the same problem.

Am I making a mistake, or am I running into a weird edge case with raycasts ?

ClosestPointOnBounds(pos) returns the closest point when pos is outside the collider. If inside the collider, it returns pos. This results in a zero length vector, which can’t be normalized - that’s the origin of the mysterious error. Anyway, colliders are single faced: a raycast from the inside doesn’t detect the collider.

EDITED: As @hoodlma pointed out, ClosestPointOnBounds(pos) returns pos when this point is inside the collider’s bounding box - it doesn’t matter whether it’s inside the actual collider or not.