I cannot execute correctly the method Save of RhinoDoc object

I am developing a function like this:

private Result SaveGeometryRhino(RhinoDoc doc, ref string ig_file_name)
        {
            if (doc.Modified)
            {
                
                if (string.IsNullOrEmpty(doc.Name))
                {
                    ig_file_name = string.Empty;
                    var save_dialog = new Rhino.UI.SaveFileDialog();
                    save_dialog.Filter = "Modelos 3D de Rhino 7 (*.3dm)|*.3dm";
                    if (save_dialog.ShowSaveDialog() == true)
                    {
                        ig_file_name = save_dialog.FileName;
                    }
                    else
                    {
                        RhinoApp.WriteLine(Properties.strings.CommandCancel, EnglishName);
                        return Result.Cancel;
                    }

                    bool ret = doc.SaveAs(ig_file_name);
                    if (ret)
                    {
                        return Result.Success;
                    }
                    else
                    {
                        return Result.Cancel;
                    }
                } else
                {
                    bool l= doc.IsLocked;
                    **bool ret = doc.Save();**
                    if (ret)
                    {
                        ig_file_name = doc.Path;
                        return Result.Success;
                    }
                    else
                    {
                        return Result.Cancel;
                    }


                }
            } else
            {
                ig_file_name = doc.Path;
            }
            return Result.Success;
        }
}

In the case of my model has changes and it has a name, I would like to do a Save.
When the method Save is executed it returns false.
I do not know when this function returns false.
I understand that it returns false if disk is full, if file is readonly, etc…It is not my case because I can use menu Save.
I have called IsLock because I though it could be the reason why Save returns false.
IsLock is true in my case but I do not why doc is lock, and if I can change this attribute without any problem.

Thanks for your attention