The issue is resolved by replacing the following lines of code
Wall w = r.Document.GetElement(bs.ElementId) as Wall; Curve curve = (w.Location as LocationCurve).Curve;
with the following code
Curve curve = bs.GetCurve();
in the Get_Room_Coordinates method.
The solution is working perfect now.
Many Thanks for the kind support.
Kind Regards
Bilal