This question is very similar to RhinoDoc.Create invalidates object ids for other RhinoDoc therefore the same answer:
If you want to create a document that is not associated with a running Rhino, use RhinoDoc.CreateHeadless(templateFile) instead of RhinoDoc.Create(templateFile)
https://developer.rhino3d.com/api/rhinocommon/rhino.rhinodoc/createheadless#(string)