RayIntersections method crash SLDWORKS 2025 OEM

I try to use the RayIntersections in C# in my ADDIN but it crashed every time (-> System access violation). I use Solidworks 2025 OEM. If I write the same code in VBA all is OK.

Someone can help me ? 

 

Here is my simplified code in C#

basePoints and dir have the same dimension. I try with this value

basePoints[0] = 0;

basePoints[1] = 0;

basePoints[2] = -0.030;  // in [m]

dir[0] = 0;

dir[1] = 0;

dir[2] = 1;

 

private static bool RayIntersectionsExt(ModelDoc2 modelDoc, Body2 targetBody, double[] basePoints, double[] dir)
{
   const double HIT_RADIUS = 1e-8;

   ModelDocExtension modelDocExt = modelDoc.Extension;

   face = null; hitPoint = null;

   object[] bodies = new object[] { targetBody };

   int intersectionCount = modelDocExt.RayIntersections(
       bodies,
       basePoints,
       dir,
       (int)(swRayPtsOpts_e.swRayPtsOptsENTRY_EXIT | swRayPtsOpts_e.swRayPtsOptsTOPOLS),
       HIT_RADIUS, 
       0.0, 
       true);

   if (intersectionCount <= 0) return false;   
}