Custom gh compounent calls a c++ writen dll , rhino crash?

i write a c# console to invoke this dll. it works well. but when i invoke this dll in gh , it makes rhino crash.
here is my c++code.

array<int>^  SAP::recogMarkerID(System::String ^path)
{
	std::string p = msclr::interop::marshal_as<std::string>(path);

	cv::Mat img = cv::imread(p, 1);

	std::vector<cv::Point2f> pts;
	std::vector<int> IDD;
	std::vector<int> IDDD;



	cSAp->recogMarkers(img, pts, IDD);
	std::vector<int> coordinates;

	if (pts.size() != 0)
	{

		for (size_t i = 0; i < IDD.size(); i++)
		{
			coordinates.push_back(IDD[i]);
			
		}
	}
	array<int>^cc = gcnew array<int>(coordinates.size()+1);;
	for (size_t i = 0; i < coordinates.size(); i++)
	{
		cc[i] = coordinates[i];
	}
	cc[coordinates.size()] = -1;
	
	return cc;
}

and this how i invoke in c# or gh

float[] p = new float[1];
  p = SS.recogMarker(path);

Is your SAP dll 32 or 64 bit?

It looks like a managed C++ library. So it should be treated as unchecked and unsafe mananged code?

64bit, and this dll runs well in a c# console application

right ,it is a managed library.
your " treated as unchecked and unsafe mananged code" is the way of call this dll in c# like the code below´╝č
unsafe
{
float[] p = new float[1];
p = SS.recogMarker(path);
}
but what i am confused is that this code can run well in a c#console app, but crush in rhino.